public CIV(Bars bars, int startTime, int stopTime, string description) public static CIV Series(Bars bars, int startTime, int stopTime)
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Components; // You must install this extension using Community.Indicators; // You must install this extensionnamespace WealthLab.Strategies { public class MyStrategy : WealthScript { StrategyParameter _days; public MyStrategy() { _days = CreateParameter("Days", 5, 2, 25, 1); } // Returns the daily average volume for the specified DataSeries and period // The average does not include the current day's period private double GetAverage(int bar, DataSeries ds, int period) { double res = 0d; for (int i = 0; i < period; i++) { // This formulation assumes that the current day's volume is not included in the average bar -= Bars.IntradayBarNumber(bar); // first bar of day bar -= 1; // last bar of previous day res += ds[bar]; } res /= period; return res; } protected override void Execute() { Utility u = new Utility( this ); // Intraday support functions here int startTime = 0930; int stopTime = 1030; int days = _days.ValueInt; double avgV = 0d; // Create a cumulative volume indicator for the intraday period (Community.Indicators) DataSeries civ = CIV.Series(Bars, startTime, stopTime); DataSeries dayAvgVol = new DataSeries(Bars, "Average Daily Volume(" + days + ")"); // Run the Strategy for(int bar = u.FirstBarofDay(days + 1); bar < Bars.Count; bar++) { int time = u.GetTime(bar); if ( time == stopTime ) { // Get the daily average for the period avgV = GetAverage(bar, civ, days); } dayAvgVol[bar] = avgV; if (IsLastPositionActive) { Position p = LastPosition; if ( Bars.IsLastBarOfDay(bar) ) { ExitAtClose(bar, p, "EOD"); } } else if ( time == stopTime && civ[bar] > dayAvgVol[bar] ) { double startPrice = Close[bar - Bars.IntradayBarNumber(bar)]; // Open price today if (Close[bar] > startPrice) BuyAtMarket(bar + 1); } } // Now created, plot the daily average volume series ChartPane dayAvgVolPane = CreatePane(40, false, true); PlotSeries(dayAvgVolPane, dayAvgVol, Color.Blue, LineStyle.Solid, 2); PlotSeries(dayAvgVolPane, civ, Color.Red, LineStyle.Solid, 1); } } }