I have an indicator that grabs data OnMarketDepth and then performs calculations on that data OnBarUpdate and plots OnBarUpdate. It plots fine if the indicator is put on a chart. However, the indicator's plot values cannot be successfully referenced from another indicator or strategy. When I attempt to do so, it returns either 0 or the close price. I have tried public DataSeries, public doubles, and Plot0 to no avail. Does anyone know why?
Here is the code that I am using in another indicator to try to reference data from the first.
private IndicatorName ir = null; protected override void OnBarUpdate() { if(Historical)return; if(ir==null)ir=IndicatorName(); Plot0.Set(IndicatorName.Plot0[0]); }
public class IndicatorName: Indicator { protected override void Initialize() { // Attach a market depth event handler if (Bars != null && Bars.MarketData != null) { marketDepth = Bars.MarketData.Connection.MarketDepthStreams[Bars.Instrument]; if (marketDepth != null) marketDepth.MarketDepthItem += new MarketDepthItemEventHandler(OnMarketDepth); } } private void OnMarketDepth(object sender, MarketDepthEventArgs e) { b = e.MarketDepth.Bid.TotalVolume(5); a = e.MarketDepth.Ask.TotalVolume(5); } protected override void OnBarUpdate() { Plot0.Set(a+b); } public override void Dispose() { // Detach the event handler if (marketDepth != null) marketDepth.MarketDepthItem -= new MarketDepthItemEventHandler(OnMarketDepth); base.Dispose(); }
Comment