I am attempting to code an Indicator that plots Daily ADR values on a 1 minute chart. I have successfully gotten the indicator to plot the daily ADR high and low values but the values of the plots extend all the way through the previous RTH session. The values change when I scroll back through the chart but I would like them to be painted on the previous RTH session without me having to scroll. Very much like the SWING indicator plots highs and lows over a time period and then changes those values as price changes while keeping the historical values on the chart.
My code is copied below. Note that I do not consider myself do be a coder. I try my best to read through the docs and reference this forum to get answers. Any help you can provide is much appreciated. Thank you!!!
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class AverageDailyRange : Indicator
{
private Series<Double> adrHigh;
private Series<Double> adrLow;
private Series<Double> openPrice;
private Series<Double> adr;
private double adrHighPlot, adrLowPlot;
protected override void OnStateChange()
{
if (State == State.SetDefaults) {
Description = @"Enter the description for your new custom Indicator here.";
Name = "Average Daily Range";
Calculate = Calculate.OnEachTick;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
PaintPriceMarkers = true;
IsSuspendedWhileInactive = true;
Lookback = 20;
AddPlot(new Stroke(Brushes.Green, DashStyleHelper.Dash, 2), PlotStyle.Line, "top");
AddPlot(new Stroke(Brushes.Red, DashStyleHelper.Dash, 2), PlotStyle.Line, "bottom");
BarsRequiredToPlot = 20;
}
else if (State == State.Configure){
AddDataSeries(null, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 }, "CME US Index Futures RTH");
}
else if (State == State.DataLoaded){
adrHigh = new Series<double>(this);
adrLow = new Series<double>(this);
openPrice = new Series<double>(this);
adr = new Series<double>(this);
}
}
protected override void OnBarUpdate()
{
if(CurrentBars[0] <= Lookback || CurrentBars[1] <= Lookback)
return;
if (BarsInProgress == 0)
{
double sum = 0;
for (int i=0; i<Lookback; i++)
sum = sum + (Highs[1][i] - Lows[1][i]);
adr[0] = Math.Round((sum/Lookback),2);
adrHigh[0] = (Opens[1][0] + (adr[0] / 2));
adrLow[0] = (Opens[1][0] - (adr[0] / 2));
// Draw.Line(this, "adrHigh" + CurrentBar.ToString(), false, 1, adrHigh[0], 0, adrHigh[0], Brushes.LimeGreen, DashStyleHelper.Dot, 4);
// Draw.Line(this, "adrLow" + CurrentBar.ToString(), false, 1, adrLow[0], 0, adrLow[0], Brushes.Red, DashStyleHelper.Dot, 4);
adrHighPlot = adrHigh[0];
adrLowPlot = adrLow[0];
Values[0][0] = adrHighPlot;
Values[1][0] = adrLowPlot;
Draw.TextFixed(this, "tag1" ,"ADR: " + adr[0] + " ADR High: " + adrHigh[0] + " ADR Low: " + adrLow[0], TextPosition.TopLeft);
}
if (BarsInProgress == 1)
{
}
}
[HASHTAG="t3322"]region[/HASHTAG] Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Lookback", Order=1, GroupName="Parameters")]
public int Lookback
{ get; set; }
[Browsable(false)]
[XmlIgnore()]
public Series<double> top
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore()]
public Series<double> bottom
{
get { return Values[1]; }
}
#endregion
}
}

Comment