Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketDepth, two similar scripts, very different results

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

    OnMarketDepth, two similar scripts, very different results

    These scripts are monitoring the changes in equal time intervals at the bid and ask

    the first example just looks at position 0 with 10millisecond gaps and store in queue.

    so position 0 is the bestbid bestoffer, correct?

    This work fines, the changes are printed to the print statement and appear to change about the same frequency.

    but the next script, only the bid seems to update in about the the same frequency as the bid on the first script, the ask is very slow on the second script. I cannot see any reason why, they are coded the same just else statements on the second script.

    the bid is timely but the ask is lagging.

    I also note that the postions go upto 9 on the emini ES contract on the ask side, and when i look at those numbers, they dont look as "orderly" as the bid side

    Tinkerz


    Code:
            protected override void OnMarketDepth(MarketDepthEventArgs e)
            {
                
            if (startbar==-1) startbar=CurrentBar;
                    
            lastcalcbar=CurrentBar;
                    
            if (ShowBidorAsk==true)
            {
            if (e.MarketDataType == MarketDataType.Ask && e.Position==0 && AskTimecounter<DateTime.Now.TimeOfDay.TotalMilliseconds)         
            {
            AskTimecounter= (DateTime.Now.AddMilliseconds(10).TimeOfDay.TotalMilliseconds);
            AskStack.Enqueue((double)e.Volume);
            int countC=AskStack.Count;
            if (countC>stacklength) 
            {    
            AskStack.Dequeue();    
            }
            Print("Asks0//"+AskStack.Count);
            }
                            
            }
            else
            {
            if (e.MarketDataType == MarketDataType.Bid && e.Position == 0  && BidTimecounter<DateTime.Now.TimeOfDay.TotalMilliseconds) 
            {
            BidTimecounter= (DateTime.Now.AddMilliseconds(10).TimeOfDay.TotalMilliseconds);            
            BidStack.Enqueue((double)e.Volume);
            int countD=BidStack.Count;
            if (countD>stacklength)
            {
            BidStack.Dequeue();
            }
            Print("Bidss0//"+BidStack.Count);
            }
            }
    
    
            }
    second script

    basically the same as the first, just splitting out the positions into queues
    Code:
            protected override void OnMarketDepth(MarketDepthEventArgs e)
            {
                
            if (startbar==-1) startbar=CurrentBar;
                    
            lastcalcbar=CurrentBar;
                
            if (ShowBidorAsk==true)
            {
            if (e.MarketDataType == MarketDataType.Ask && AskTimecounter<DateTime.Now.TimeOfDay.TotalMilliseconds)         
            {
            AskTimecounter= (DateTime.Now.AddMilliseconds(10).TimeOfDay.TotalMilliseconds);
    //        Print("Asks0postion//"+e.Position);    
            if (e.Position==0)             
                    {
                    AskLimit0=e.Volume;                        
                    AskStack0.Enqueue((double)e.Volume);
                    countC0=AskStack0.Count;            
                    if (countC0>stacklength) 
                    {
                    AskStack0.Dequeue();    
                    }
                    Print("Asks0//"+AskStack0.Count);
                    }
                    else
            if (e.Position==1)             
                    {
                    AskLimit1=e.Volume;                        
                    AskStack1.Enqueue((double)e.Volume);
                    countC1=AskStack1.Count;            
                    if (countC1>stacklength) 
                    {    
                    AskStack1.Dequeue();    
                    }
    //                Print("Asks1//"+AskStack1.Count);
                    }
                    else
            if (e.Position==2)             
                    {
                    AskLimit2=e.Volume;                            
                    AskStack2.Enqueue((double)e.Volume);
                    countC2=AskStack2.Count;            
                    if (countC2>stacklength) 
                    {    
                    AskStack2.Dequeue();    
                    }
    //                Print("Asks2//"+AskStack2.Count);
                    }
                    else
            if (e.Position==3)             
                    {
                    AskLimit3=e.Volume;                            
                    AskStack3.Enqueue((double)e.Volume);
                    countC3=AskStack3.Count;            
                    if (countC3>stacklength) 
                    {    
                    AskStack3.Dequeue();    
                    }
    //                Print("Asks3//"+AskStack3.Count);                
                    }
                    else
            if (e.Position==4)             
                    {
                    AskLimit4=e.Volume;                    
                    AskStack4.Enqueue((double)e.Volume);
                    countC4=AskStack4.Count;            
                    if (countC4>stacklength) 
                    {    
                    AskStack4.Dequeue();    
                    }
    //                Print("Asks4//"+AskStack4.Count);                    
                    }    
            }
            }
            else
            if (e.MarketDataType == MarketDataType.Bid  && BidTimecounter<DateTime.Now.TimeOfDay.TotalMilliseconds) 
            {
            BidTimecounter= (DateTime.Now.AddMilliseconds(10).TimeOfDay.TotalMilliseconds);//
    //        Print("Bids0postion//"+e.Position);    
                if ( e.Position == 0) 
                {
                    BidLimit0=e.Volume;                
                    BidStack0.Enqueue((double)e.Volume);
                    countD0=BidStack0.Count;
                    if (countD0>stacklength)
                    {
                    BidStack0.Dequeue();
                    }
                Print("Bids//"+BidStack0.Count);
                }
                else
                if ( e.Position == 1) 
                {
                    BidLimit1=e.Volume;                
                    BidStack1.Enqueue((double)e.Volume);
                    countD1=BidStack1.Count;
                    if (countD1>stacklength)
                    {
                    BidStack1.Dequeue();
                    }
                }
                            else
                if ( e.Position == 2) 
                {
                    BidLimit2=e.Volume;                
                    BidStack2.Enqueue((double)e.Volume);
                    countD2=BidStack2.Count;
                    if (countD2>stacklength)
                    {
                    BidStack2.Dequeue();
                    }
                }
                            else
                if ( e.Position == 3) 
                {
                    BidLimit3=e.Volume;
                    BidStack3.Enqueue((double)e.Volume);
                    countD3=BidStack3.Count;
                    if (countD3>stacklength)
                    {
                    BidStack3.Dequeue();
                    }
                }
                            else
                if ( e.Position == 4) 
                {
                    BidLimit4=e.Volume;
                    BidStack4.Enqueue((double)e.Volume);
                    countD4=BidStack4.Count;
                    if (countD4>stacklength)
                    {
                    BidStack4.Dequeue();
                    }
                }
            }
    
    
    //            try{ChartControl.Refresh();}
    //            try{}
    //            catch {}
        
            }

    #2
    tinkerz, didn't spot anything on first sight - if you simplify the second script to work only on one side of the book, do those differences persist?

    Comment


      #3
      I have made 2 individual scripts, one for ask and one for bid, just taking out the boolean "showbidorask"

      There is still a noticeable difference in Ask to bid changes, ask is much slower

      Comment


        #4
        tinkerz, on which feed and instruments are you testing?

        Do you see the same happen with our samples provided for this?

        Comment


          #5
          Code:
                  if (e.MarketDataType == MarketDataType.Ask && AskTimecounter<DateTime.Now.TimeOfDay.TotalMilliseconds && e.Position==0)          
                  {
                  AskTimecounter= (DateTime.Now.AddMilliseconds(10).TimeOfDay.TotalMilliseconds);
          //        Print("Asks0postion//"+e.Position);    
          //        if (e.Position==0)             
                          {
                          AskLimit0=e.Volume;                        
                          AskStack0.Enqueue((double)e.Volume);
                          countC0=AskStack0.Count;            
                          if (countC0>stacklength) 
                          {
                          AskStack0.Dequeue();    
                          }
                          Print("Asks0///////////////"+AskStack0.Count);
                          Print("Asks0///////////////"+e.Price);                
                          }
          This is faster than
          Code:
                  if (e.MarketDataType == MarketDataType.Ask && AskTimecounter<DateTime.Now.TimeOfDay.TotalMilliseconds && e.Position<5)         
                  {
                  AskTimecounter= (DateTime.Now.AddMilliseconds(10).TimeOfDay.TotalMilliseconds);
          //        Print("Asks0postion//"+e.Position);    
                  if (e.Position==0)             
                          {
                          AskLimit0=e.Volume;                        
                          AskStack0.Enqueue((double)e.Volume);
                          countC0=AskStack0.Count;            
                          if (countC0>stacklength) 
                          {
                          AskStack0.Dequeue();    
                          }
                          Print("Asks0"+AskStack0.Count);
                          }
          so its the decleration in the e.Position==0 in the first IF statement, this is odd?

          Comment


            #6
            ES-Mini, there are only updates as there are no marketmakers, which is even more curious

            Comment


              #7
              Error on calling 'OnMarketDepth' method for indicator 'SampleMarketDepth': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.


              on ES-mini with script Samplemarketdepth_NT7

              Comment


                #8
                tinkerz, I believe we applied a fix especially in this regard, can you please try running the script without having a dedicated DOM open at the same point in time?

                Comment


                  #9
                  the Samplemarketdepth_NT7 script?

                  I dont have a DOM open anyway

                  Comment


                    #10
                    ok I have found it

                    its the time function, on seperating out the positions in else statements, the timer function updates on all updates, therefore it is always advancing, and appears not to update, but its updated to often to let the statement trigger properly

                    need to look at it again though, but thats what is seems is happening

                    Comment


                      #11
                      tinkerz,

                      I guess I did not quite follow what you meant, but please let us know should you need some clarification on the sample code. Thank you.
                      Josh P.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      602 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      347 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      103 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      559 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      558 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X