Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

onmarketdepth data cannot be referenced

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    onmarketdepth data cannot be referenced

    Hello.

    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.

    Code:
    private IndicatorName ir = null;
            protected override void OnBarUpdate()
            {
    			if(Historical)return;
    			if(ir==null)ir=IndicatorName();
                            Plot0.Set(IndicatorName.Plot0[0]);
            }
    and the indicator code itself is something like this
    Code:
    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();
    		}
    Last edited by honvl; 12-09-2008, 10:42 PM.

    #2
    I think the Tech Support guys have mentioned many times not to process data in the Initialize() section. You may want to consider moving that code.

    Comment


      #3
      Hi honvl,

      Thank you for posting your code - please review this reference sample from our forum - http://www.ninjatrader-support2.com/...ead.php?t=4991
      BertrandNinjaTrader Customer Service

      Comment


        #4
        I've discovered the issue. There was a
        ChartControl.ChartPanel.Invalidate();
        line in my indicator, a remnant from the original agOrderBookOscillator indicator that I developed my indicator from. I don't know what that line does, but it was eliminating the data. Once I removed it, data calls worked as usual. Thanks for your assistance, TAJTrades and Bertrand!

        Comment


          #5
          Great you got it resolved honvl!
          BertrandNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by kempotrader, Today, 08:56 AM
          0 responses
          6 views
          0 likes
          Last Post kempotrader  
          Started by kempotrader, Today, 08:54 AM
          0 responses
          4 views
          0 likes
          Last Post kempotrader  
          Started by mmenigma, Today, 08:54 AM
          0 responses
          2 views
          0 likes
          Last Post mmenigma  
          Started by halgo_boulder, Today, 08:44 AM
          0 responses
          1 view
          0 likes
          Last Post halgo_boulder  
          Started by drewski1980, Today, 08:24 AM
          0 responses
          4 views
          0 likes
          Last Post drewski1980  
          Working...
          X