Or is there a way to reference this indicator applied to a specific instrument within another indicator that can then average them? Thanks.
namespace NinjaTrader.NinjaScript.Indicators { public class NetVolDeltaPercent : Indicator { private double buys; private double sells; private int activeBar = 0; private Series<double> Buys; private Series<double> TotalVol; private Series<double> CumNet; private Series<double> CumVol; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Cumulative Net Vol Delta as a Percent of Total Vol."; Name = "Net Vol Delta Percent"; 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 = false; Periods = 25; AddPlot(Brushes.Gainsboro, "Plot1"); AddPlot(Brushes.DarkGray, "Plot2"); } else if (State == State.Historical) { if (Calculate != Calculate.OnEachTick) { Draw.TextFixed(this, "NinjaScriptInfo", string.Format(NinjaTrader.Custom.Resource.NinjaScr iptOnBarCloseError, Name), TextPosition.BottomRight); Log(string.Format(NinjaTrader.Custom.Resource.Ninj aScriptOnBarCloseError, Name), LogLevel.Error); } } else if (State == State.Configure) { } else if (State == State.DataLoaded) { Buys = new Series<double>(this); TotalVol = new Series<double>(this); CumNet = new Series<double>(this); CumVol = new Series<double>(this); } } protected override void OnMarketData(MarketDataEventArgs e) { if(e.MarketDataType == MarketDataType.Last) { if(e.Price >= e.Ask) buys += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume); else if (e.Price <= e.Bid) sells += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume); } } protected override void OnBarUpdate() { if (CurrentBar < activeBar || CurrentBar <= BarsRequiredToPlot) return; if (CurrentBar != activeBar) { Buys[1] = buys - sells; TotalVol[1] = buys + sells; buys = 0; sells = 0; activeBar = CurrentBar; } Buys[0] = buys - sells; TotalVol[0] = buys + sells; if (Bars.BarsSinceNewTradingDay == 1) { CumNet[0] = Buys[1]; CumVol[0] = TotalVol[1]; } else if (Bars.BarsSinceNewTradingDay >= 1) { CumNet[0] = CumNet[1] + Buys[1]; CumVol[0] = CumVol[1] + TotalVol[1]; } if (Bars.BarsSinceNewTradingDay > 50) { Plot1[0] = ((CumNet[0] / CumVol[0]) * 100); Plot2[0] = 0; } }
Comment