Thanks to AlanP, I was able to create this ATR which uses an SMA for calculation (attached). I'm now trying to get that indicator to always use daily bars for calculation, but I'm doing something wrong. I thought I'd added the second data series correctly (see code below) and pointed my variables to it, but 2 issues keep cropping up. First, I can't compile the code as it is because three variables (double high0, double low0, and close1) are throwing an error that says indexing can't be applied to a double. If I change the values of those variables to Highs [1][0], Lows[1][0], and Closes[1][0] instead of High[1][0], Low[1][0], and Close[1][0], I can get it to compile, but the indicator is blank when I apply it to a chart.
I'll paste my code below. Any guidance would be greatly appreciated.
{
private Series <double> trueRangeSeries;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionATR;
Name = "AWO ATR Daily";
IsSuspendedWhileInactive = true;
Period = 5;
AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meATR);
trueRangeSeries = new Series<double>(this);
}
else if (State==State.Configure)
{
AddDataSeries(BarsPeriodType.Day, 1);
}
}
protected override void OnBarUpdate()
{
double high0 = High[1][0];
double low0 = Low[1][0];
if (CurrentBar == 0)
Value[0] = high0 - low0;
else
{
double close1 = Close[1][0];
double trueRange = Math.Max(Math.Abs(low0 - close1), Math.Max(high0 - low0, Math.Abs(high0 - close1)));
trueRangeSeries[0] = trueRange;
Value[0] = SMA(trueRangeSeries,Period)[0];
}
}
Comment