public class DailyATR2 : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Add a Daily bars object and calculate ATR";
Name = "Daily ATR2";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
IsSuspendedWhileInactive = true;
BarsRequiredToPlot = 14;
}
else if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Day, 1);
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < BarsRequiredToPlot || CurrentBars[1] < BarsRequiredToPlot) //(CurrentBars[1] < 14)//
{
Print("The current daily bar is " + CurrentBars[1]);
Print("The Time is " + Time[0]);
}
else
{
var dailyATR = ATR(BarsArray[1], 14)[0];
Print("The current daily bar is " + CurrentBars[1]);
Print("The time is " + Time[0]);
Print("The Daily ATR is " + dailyATR);
}
// This is working but it requires far more bars than expected in order to work. Investigate tomorrow.
}
region Properties
#endregion
}
As can be seen in the output windows below the indicator starts on the 01/12/2022 and ends on the 30th (28 and a bit days of data) but the bar count if only 18? and the barscount starts at -1?
Thankyou
Comment