CIV (Cumulative Intraday Volume)

Modified on 2010/09/13 15:32 by Eugene — Categorized as: Community Indicators

Syntax

public CIV(Bars bars, int startTime, int stopTime, string description) public static CIV Series(Bars bars, int startTime, int stopTime)

Parameter Description

Bars A Bars object
startTime Start time
stopTime Stop time

Description

Sums volume from start to stop times, and holds the result constant until it is reset the following day. CIV is the Cumulative Intraday Volume between the supplied start and stop times. Use in conjunction with SetScaleDaily to determine the average daily volume during a specified time interval, for example.

Note! A problem exists in the SetScale* functions in WL5.6 (and possibly previous versions). Indicators created in the higher scale returns an indicator applied to the data in the lower scale, in effect nullifying the SetScale operation.

Example

The strategy simply buys at 10:30 am if the current price is greater than the opening price, but only if today's CIV volume is greater than the average CIV volume. The example contains a work-around for the SetScale* problem that computes the average volume for a specified number of days (see Note! above).

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 extension

namespace 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 += dsbar; } 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); } dayAvgVolbar = avgV; if (IsLastPositionActive) { Position p = LastPosition; if ( Bars.IsLastBarOfDay(bar) ) { ExitAtClose(bar, p, "EOD"); } } else if ( time == stopTime && civbar > dayAvgVolbar ) { double startPrice = Closebar - Bars.IntradayBarNumber(bar); // Open price today if (Closebar > 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); } } }