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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      89 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X