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 NullPointStrategies, Today, 05:17 AM
      0 responses
      38 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      124 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      64 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      41 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X