Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trading on level 2 values

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

    #91
    thanks,


    ok so I found the error that was creating so much annoyance.

    in
    PHP Code:
     private void updateOrderBook(MarketDepthEventArgs e) {
    
    // standard lvl2 book  stuff
    
    for(int idx=0;idx < askRows.Count; idx++){
                        Print("         ----------------- 7a --------              ");
                        ask_v_safe[idx] = askRows[idx].Volume;
                        Print("         ----------------- 7b --------              ");
                        ask_p_safe[idx] = askRows[idx].Price;
                        Print("         ----------------- 7c --------              ");
                        bid_v_safe[idx] = bidRows[idx].Volume;
                        Print("         ----------------- 7d --------              ");
                        bid_p_safe[idx] = bidRows[idx].Price;
                        Print("         ----------------- 7e --------              ");
                    }                
                    Print("         ----------------- 8 --------              ");
    } 
    
    which is simply the standard code you guys game me with the added part at the end to record the ask and bid so I can physically record it

    I get this error once and a while


    25/02/2013 4:15:32 AM Strategy Error on calling 'OnMarketDepth' method for strategy 'datalvl2quantity/e59fb45b6f504ee88170d985b7f4da7f': 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.


    help.

    Comment


      #92
      I haven't been able to reproduce the error on my end. Could you please provide me with the .cs file you're using or a simpler one which reproduces the error so I can do further testing?

      Located in (MY)Documents\NinjaTrader 7\bin\Custom\(Indicator or Strategy)
      LanceNinjaTrader Customer Service

      Comment


        #93
        Hi Sorry for the late reply,

        I included the section of the code. apart from what I have added, the strat is doing nothing else. but yet I still get an error.


        all im trying to do is to save the lvl2 data bid , ask price and volume .

        the error sometimes takes place instantly, or after 5 minutes or 4 hours .... very annoying


        this is the log when it instantly:
        01/04/2013 8:22:34 AM Strategy Enabling NinjaScript strategy 'test504/db0f84c6ff4a477ab55597fa3ed6f3ee' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=4 in 5 minutes

        01/04/2013 8:22:34 AM Strategy Error on calling 'OnMarketDepth' method for strategy 'test504/db0f84c6ff4a477ab55597fa3ed6f3ee': 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.


        of after a few minutes
        01/04/2013 8:02:08 AM Strategy Enabling NinjaScript strategy 'test504/db0f84c6ff4a477ab55597fa3ed6f3ee' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=4 in 5 minutes

        01/04/2013 8:18:21 AM Strategy Error on calling 'OnMarketDepth' method for strategy 'test504/db0f84c6ff4a477ab55597fa3ed6f3ee': 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.




        using patsystem
        Attached Files
        Last edited by chancehero; 04-01-2013, 05:45 AM.

        Comment


          #94
          also, what do I need to add to this code, to remove the 20 event when the book is updating. let me know if you need more details.

          when price changes , the lvl2 book shifts prices and you get double prices at some spots, how do I skip that updating - so that I end up with the real book.
          Attached Files

          Comment


            #95
            when there are larger changes in price I get errors.

            Comment


              #96
              Hello,

              I do receive the same error when running your script and have also isolated it to the following as it sounds you are aware.

              Code:
              				if(count_save <= 20)
              					return;
              				string data_lvl2 = count_save /* +" , "+ DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt") */
              			+	" price bid 0 " + bidRows[0].Price  + " quantity bid 0 " + bidRows[0].Volume + " price ask 0 " + askRows[0].Price  + " quantity ask 0 " + askRows[0].Volume    
              			+	" price bid 1 " + bidRows[1].Price  + " quantity bid 1 " + bidRows[1].Volume + " price ask 1 " + askRows[1].Price  + " quantity ask 1 " + askRows[1].Volume 
              			+	" price bid 2 " + bidRows[2].Price  + " quantity bid 2 " + bidRows[2].Volume + " price ask 2 " + askRows[2].Price  + " quantity ask 2 " + askRows[2].Volume 
              			+	" price bid 3 " + bidRows[3].Price  + " quantity bid 3 " + bidRows[3].Volume + " price ask 3 " + askRows[3].Price  + " quantity ask 3 " + askRows[3].Volume 
                          +	" price bid 4 " + bidRows[4].Price  + " quantity bid 4 " + bidRows[4].Volume + " price ask 4 " + askRows[4].Price  + " quantity ask 4 " + askRows[4].Volume 
              			+	" price bid 5 " + bidRows[5].Price  + " quantity bid 5 " + bidRows[5].Volume + " price ask 5 " + askRows[5].Price  + " quantity ask 5 " + askRows[5].Volume 
              			+	" price bid 6 " + bidRows[6].Price  + " quantity bid 6 " + bidRows[6].Volume + " price ask 6 " + askRows[6].Price  + " quantity ask 6 " + askRows[6].Volume 
                          +	" price bid 7 " + bidRows[7].Price  + " quantity bid 7 " + bidRows[7].Volume + " price ask 7 " + askRows[7].Price  + " quantity ask 7 " + askRows[7].Volume 
              			+	" price bid 8 " + bidRows[8].Price  + " quantity bid 8 " + bidRows[8].Volume + " price ask 8 " + askRows[8].Price  + " quantity ask 8 " + askRows[8].Volume 
              			+	" price bid 9 " + bidRows[9].Price  + " quantity bid 9 " + bidRows[9].Volume + " price ask 9 " + askRows[9].Price  + " quantity ask 9 " + askRows[9].Volume 
                          + Environment.NewLine ;
              			File.AppendAllText(log_file_lvl2book,data_lvl2 );
              I know you said we gave you this code but I haven't been able to locate where we use it. If you could point this out I will look further into this.

              You will need to add error checking with each one of these individual rows to isolate what is the cause for the out of bounds error.



              You cannot assume all of these points will be valid on each call.

              Let me know if I can be of further assistance.
              LanceNinjaTrader Customer Service

              Comment


                #97
                except from what you have isolated. (that is mine), the rest is from NT standard lvl 2 book code.

                the problem is at the fist lvl2 level , bid[0] and ask[0] , when price changes very fast. but it is weird that I can use this bidRows[0].Volume and .Price to calculate other variables but if I want to save them , I get errors....


                same ideal as
                Last edited by chancehero; 04-01-2013, 12:39 PM.

                Comment


                  #98
                  Hello,

                  Thank you for the additional report.
                  We'll follow up once we have more information.
                  LanceNinjaTrader Customer Service

                  Comment


                    #99
                    Hello,

                    I've noticed the script you're using is different than the one we provide in the SampleMarketDepth

                    In our script it will print out the number of bid/askRows based on the total size of the book.

                    Your script prints the first 10 indexes regardless of the size.

                    The full script you posted is different than the script you referenced here:


                    PHP Code:
                     private void updateOrderBook(MarketDepthEventArgs e) {
                    
                    // standard lvl2 book  stuff
                    
                    for(int idx=0;idx < askRows.Count; idx++){
                                        Print("         ----------------- 7a --------              ");
                                        ask_v_safe[idx] = askRows[idx].Volume;
                                        Print("         ----------------- 7b --------              ");
                                        ask_p_safe[idx] = askRows[idx].Price;
                                        Print("         ----------------- 7c --------              ");
                                        bid_v_safe[idx] = bidRows[idx].Volume;
                                        Print("         ----------------- 7d --------              ");
                                        bid_p_safe[idx] = bidRows[idx].Price;
                                        Print("         ----------------- 7e --------              ");
                                    }                
                                    Print("         ----------------- 8 --------              ");
                    } 
                    
                    This code snippet is closer to correct but you are making the assumption that bid and ask rows are the exact same size. You cannot make this assumption and will need to handle them differently.
                    LanceNinjaTrader Customer Service

                    Comment


                      thanks ! that is starting to make sense

                      so I should do something like what I have below
                      since I want to simply record it to a text file for future use I could do something like :

                      PHP Code:
                      for(int idx=0;idx < askRows.Count; idx++){ 
                      string data_ask = "aq"+idx+askRows[idx].Volume + "ap"+idx+askRows[idx].Price;
                      File.AppendAllText(log_file_lvl2_book,data_ask );
                      }
                      for(int idx=0;idx < bidRows.Count; idx++){ 
                      string data_bid = "bq"+idx+bidRows[idx].Volume + "bp"+idx+bidRows[idx].Price;
                      File.AppendAllText(log_file_lvl2_book,data_bid );
                      }
                      string data_newline = Environment.NewLine ;
                      File.AppendAllText(log_file_lvl2_book,data_newline ); 
                      
                      Last edited by chancehero; 04-02-2013, 10:37 AM.

                      Comment


                        I haven't tested it on my end but it does look like this would be correct.

                        Let me know if I can be of further assistance.
                        LanceNinjaTrader Customer Service

                        Comment


                          now things work well,

                          used streamwriter and made a giant difference,

                          I build the book ==> done
                          I record the book ==> done

                          question:


                          if I want to have a cumulative depth like the dynamic superDOM at the 5th level, how should I proceed?

                          thanks

                          Comment


                            You would need to manually add up all the rows and output them to a new item. There is not a method for collecting/displaying cumulative data so you're going to have to emulate what you see us doing in the DOM.
                            MatthewNinjaTrader Product Management

                            Comment


                              something like this should do the trick ?

                              PHP Code:
                              //===========================================================
                                              //                      ||
                                              //                     ||
                                              //                    \/
                                              //                new addition to code
                                              // up to lvl 5 , like in the superDOM
                                              // check if you have enough rows, Yes: proceed
                                              int level_search = 5;
                                              if(askRows.Count >= level_search){
                                                  double askvol5 = 0;
                                                  // add the first 5 rows
                                                  for(int idx =0; idx < level_search, idx++){
                                                      askvol5 +=askRows[idx].Volume;
                                                  }
                                              }
                              
                                              if(bidRows.Count >= level_search){
                                                  double bidvol5 = 0;
                                                  // add the first 5 rows
                                                  for(int idx =0; idx < level_search, idx++){
                                                      bidvol5 +=bidRows[idx].Volume;
                                                  }
                                              }
                                              //                      ^
                                              //                     |
                                              //                    |
                                              //                new addition to code
                                              //=========================================================== 
                              

                              Comment


                                place the double outside the if loop or you want be able to call it

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                626 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                359 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
                                562 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                567 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X