Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SampleLevel2Book - access data in strategy script

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

    SampleLevel2Book - access data in strategy script

    Hi

    Topic to discuss: how to retrieve in a strategy the volume per price from the SampleLevel2Book indicator

    I have tried the following to get the bid for the first row:

    *code written when declaring variables
    private SampleLevel2Book SampleLevel2Book1;

    *code written under “State == State.DataLoaded”:
    SampleLevel2Book1=SampleLevel2Book(Close);

    *code written under ”OnbarUpdate()”
    bid1=SampleLevel2Book1.bidRows[1].Volume;

    I then use bid1 in a condition to trigger buy/sell orders

    When i compile the strategy there are no errors, however when launching the strategy i get the following error: “Error on calling “OnBarUpdate method on bar 1: you are accessing an index with a value that is invalid since it is out of range”

    Am i using the indicator correctly?

    #2
    Hello MacroTrader347,

    That is the correct way to use the list however you need to make sure its populated first.

    You could make a condition that checks the count like the following:

    Code:
    if (rows.Count > 1)
    {
    
    }


    Comment


      #3
      Hi Jesse, Thank you for coming back. I have added your mentioned logic in my code and can confirm the strategy works properly now. Many thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      21 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      41 views
      0 likes
      Last Post CarlTrading  
      Working...
      X