Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Try Catch and OnMarketdepth

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

    Try Catch and OnMarketdepth

    I am using 3 event statements in 1 script

    Onbarupdate
    Onmarketdata
    Onmarketdepth

    I am only collecting data into my queue when the update event occurs.

    I thought if you apply these 3 seperatly you will get streaming data?

    But at the moment I am not, is it the update event that makes the queue fill up?

    I am also going to try to include the below code, i just want to snapshot the depth volume at position zero

    Tinkerz

    Code:
            protected override void OnMarketDepth(MarketDepthEventArgs e)
            {            
            if (e.MarketDataType == MarketDataType.Ask && e.Position == 0) 
            {
            AskStack.Enqueue((double)e.Volume);
            int countC=AskStack.Count;
            AskTime.Enqueue(Math.Round(DateTime.Now.TimeOfDay.TotalSeconds,0));
            if (countC>128) 
            {    
            AskStack.Dequeue();    
            AskTime.Dequeue();                
            }
            }
            if (e.MarketDataType == MarketDataType.Bid && e.Operation == Operation.Update && e.Position == 0) 
            {
            BidStack.Enqueue(e.Volume);
            int countD=BidStack.Count;
            if (countD>128) BidStack.Dequeue();    
            }    
                if (timestart<(DateTime.Now.TimeOfDay.TotalSeconds));
                try{ChartControl.Refresh();}
    
                catch {}
                timestart = (DateTime.Now.AddSeconds(1).TimeOfDay.TotalSeconds);        
            }

    #2
    tinkerz,

    I am not exactly sure what you are trying to do with the queue.

    I suggest you check out this reference sample for making an L2 book. If you only want the info at position zero, just disregard the code for all the other levels. http://www.ninjatrader-support2.com/...ead.php?t=3478
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I am using the collection type queue, to hold the events on position 0 of the Ask and Bid, and hold them at a constant size for analysis.

      The queue collection only updates when the Onbarupdate event occurs not when the OnMarketDepth occurs, which is more frequent.

      which leads me to think that I need to do something for the queue to fill up in realtime, later I will add a delay but for now it seems the Onbarupdate is event is the only event that makes the queues fill

      protected override void OnMarketDepth(MarketDepthEventArgs e)
      {
      if (e.MarketDataType == MarketDataType.Ask && e.Position == 0)
      {
      AskStack.Enqueue((double)e.Volume);

      Comment


        #4
        tinkerz,

        You are working with objects that is more advanced C# and not NinjaScript. Unfortunately this is outside the scope of what we can support and I would not know.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Ok I understand that it is outside of support.

          Please can you tell me is the OnMarketDepth(MarketDepthEventArgs e)
          works independently of Onbarupdate.

          What I mean is what makes the script calculate?

          Is the price tick, so when a script runs its from a last sale? then OnMarketDepth collects the data?

          Comment


            #6
            Hello Tinkerz,

            OnBarUpdate() is called on updates to level one data: OHLC and volume.

            OnMarketDepth() is called on updates to level II or market depth data.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            633 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            567 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X