I have an indicator that calculates for each day a value that I want to plot from the first candle of the day until the end of the day.
I use a tick chart (so the number of bars will change for each day).
I tried to use a counter that resets for each session with Bars.IsFIrstBarOfSession, as well as a counter of all the bars we have loaded on the chart to have my lines plotted dynamically, but it doesn't work. If I understand correctly, CurrentBar is going from left to right, but is it updated at each new candle close Or are the values fixed 'forever'?
Any idea of where the code is wrong?
public class pdh : Indicator { private int numberOfBars = 0; private int totalNumberOfBars = 0; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "pdh"; Calculate = Calculate.OnBarClose; IsOverlay = true; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; AddPlot(new Stroke(Brushes.Green, DashStyleHelper.Solid, 1, 100), PlotStyle.Bar, "MyPlot"); } else if (State == State.Configure) { AddDataSeries(null, new BarsPeriod() { BarsPeriodType = BarsPeriodType.Day, Value = 1}, 10, null, null); } } protected override void OnBarUpdate() { if (CurrentBars[0] < 1 || CurrentBars[1] < 5) return; if(BarsInProgress == 1) return; double avgHighs = 0; for (int i = 0; i < 5; i++) { avgHighs += Highs[1][i]; } avgHighs = avgHighs/5; if (Bars.IsFirstBarOfSession) { numberOfBars = 0; } numberOfBars++; totalNumberOfBars++; Print("Number of bars: " + numberOfBars); Print("CurrentBar: " + CurrentBar); Draw.Line(this, "highs" + CurrentBar, false, CurrentBar - numberOfBars, avgHighs, CurrentBar, avgHighs, new SolidColorBrush(Color.FromRgb(209, 212, 220)), DashStyleHelper.Dash, 2); } }
Many thanks.
Comment