I am calculating ATR using 1 min and 5 min data series. I followed the steps in the help pages. However, the ATR of primary series is always 0 whereas the secondary series is properly calculated. Would you please help?
Here is the relevant part in OnStateChange()
// Find the Sim101 account
lock (Account.All)
myAccount = Account.All.FirstOrDefault (a => a.Name == "Sim101");
}
else if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Minute, 5);
}
else if (State == State.DataLoaded)
{
// initialize the ATR using the primary series and assign to atr1
atr1 = ATR(BarsArray[0], 14);
// initialize the SMA using the secondary 5 minute series and assign to atr1
atr2 = ATR(BarsArray[1], 14);
}
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
// ensure both series have at least one bar
if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
return;
// when the 5 minute series is processing set the secondary plot to the atr with the secondary series input
if (BarsInProgress == 1)
ATRSecondary[0] = atr2[0];
// when the primary series is processing set the primary plot to the atr with the primary series input
if (BarsInProgress == 0)
{
ATRPrimary[0] = atr1[0];
// if the secondary 5 minute series did not close, set the current bar's value to the previous bar's value to prevent gaps
if (!ATRSecondary.IsValidDataPoint(0))
ATRSecondary[0] = ATRSecondary[1];
}
if (State == State.Historical || CurrentBar < 14)
return;
Print(ATRPrimary[1]);
Thank you.

Comment