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

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 DanielSanMartin, Yesterday, 02:37 PM
            2 responses
            12 views
            0 likes
            Last Post DanielSanMartin  
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            11 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            7 views
            0 likes
            Last Post nandhumca  
            Started by The_Sec, Today, 03:37 PM
            0 responses
            3 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Working...
            X