I want to connect high/low pivots on OBV indicator together, if new high pivot is higher than previous high pivot it should connect by green line if lower connect by red line
here is indicator code
private int prevSWH = -1; private int prevSWL = -1; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"TheMavisV3.0"; Name = "MavisNT"; Calculate = Calculate.OnEachTick; IsOverlay = false; 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(Brushes.Transparent, "OBV"); AddPlot(Brushes.Black, "OBV_UP"); AddPlot(Brushes.Magenta, "OBV_DN"); AddPlot(new Stroke(Brushes.Green, DashStyleHelper.Solid, 2), PlotStyle.TriangleDown, "SWH_UP"); AddPlot(Brushes.Red, "SWH_DN"); AddPlot(Brushes.Green, "SWL_UP"); AddPlot(Brushes.Red, "SWL_DN"); Plots[1].Width=2; Plots[2].Width=2; } else if (State == State.Configure) { } } protected override void OnBarUpdate() { //Add your custom indicator logic here. double volume0 = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]; if (CurrentBar == 0) { OBV[0]=volume0; OBV_UP[0]=volume0; OBV_DN[0]=volume0; SWH_UP[0]=0; SWH_DN[0]=0; SWL_UP[0]=0; SWL_DN[0]=0; prevSWH=-1; prevSWL=-1; } else { if ((High[0]-Open[0])>(Open[0]-Low[0])) OBV[0]=OBV[1]+volume0; else if ((High[0]-Open[0])<(Open[0]-Low[0])) OBV[0]=OBV[1]-volume0; else OBV[0]=OBV[1]; OBV_UP[0]=OBV[0]; OBV_DN[0]=OBV[0]; if (IsRising(OBV)) { PlotBrushes[1][0]=Brushes.Black; PlotBrushes[2][0]=Brushes.Transparent; } else if (IsFalling(OBV)) { PlotBrushes[1][0]=Brushes.Transparent; PlotBrushes[2][0]=Brushes.Magenta; } else { PlotBrushes[1][0]=PlotBrushes[1][1]; PlotBrushes[2][0]=PlotBrushes[2][1]; } if (CurrentBar>3) { if (OBV[2]>OBV[3] && OBV[2]>OBV[1] && prevSWH!=CurrentBar-2) { if (prevSWH!=-1 && OBV[2]>=OBV[CurrentBar-prevSWH]) { SWH_UP[2]=OBV[2]; SWH_UP[CurrentBar-prevSWH]=OBV[CurrentBar-prevSWH]; } else if (prevSWH!=-1 && OBV[2]<=OBV[CurrentBar-prevSWH]) { SWH_DN[2]=OBV[2]; SWH_DN[CurrentBar-prevSWH]=OBV[CurrentBar-prevSWH]; } prevSWH = CurrentBar-2; } } } }
image below show how indicator looks like when I choose Line style for that plot (there is no line drawn)
this is part of coed that handles detecting pivots and filling related data series
if (CurrentBar>3) { if (OBV[2]>OBV[3] && OBV[2]>OBV[1] && prevSWH!=CurrentBar-2) { if (prevSWH!=-1 && OBV[2]>=OBV[CurrentBar-prevSWH]) { SWH_UP[2]=OBV[2]; SWH_UP[CurrentBar-prevSWH]=OBV[CurrentBar-prevSWH]; } else if (prevSWH!=-1 && OBV[2]<=OBV[CurrentBar-prevSWH]) { SWH_DN[2]=OBV[2]; SWH_DN[CurrentBar-prevSWH]=OBV[CurrentBar-prevSWH]; } prevSWH = CurrentBar-2; } }
Comment