I have a query. I would like to extract daily average volume and use it in Ninja script which runs on 3 minute chart. Right now I have added Add(PeriodType.Day,1); as my secondary data series with barsinprogress index as 1.
Following is the code for the initialize() function :
protected override void Initialize()
{
CalculateOnBarClose = false;
stopLossPercent = 0.15;
Add(PeriodType.Day,1);
Add(PeriodType.Minute,1);
[B]averageDailyVolume = SMA(Volumes[1],20);[/B]
slowMovingAverage = SMA(Closes[0],slowmovingaverage);
maEnvelopes = MAEnvelopes(Closes[0],envelopeoffset,3,envelopemovingaverage);
SetStopLoss(CalculationMode.Percent,stopLossPercent);
}
Code :
protected override void OnBarUpdate()
{
if (CurrentBars[1] < 20)
return;
if(nStatus == 0 && entryFlag == 0)
{
if(this.checkShortEntry())
{
[B]if(averageDailyVolume[1] >= thresholdVolume)[/B]
{
entryFlag = -1;
}
}
else if(this.checkLongEntry())
{
[B]if(averageDailyVolume[1] >= thresholdVolume)[/B]
{
entryFlag = 1;
}
}
}
}
Thanks and Regards,
Vipin

Comment