Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SampleMarketDepth

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

    SampleMarketDepth

    I'm using your SampleMarketDepth script and just added a couple of simple lines, but get an error I can not explain. All I did was add this at the end;

    double AskPrice0 = e.MarketDepth.Ask[0].Volume;
    double AskPrice1 = e.MarketDepth.Ask[1].Volume;
    double AskPrice2 = e.MarketDepth.Ask[2].Volume;
    double AskPrice3 = e.MarketDepth.Ask[3].Volume;
    double AskPrice4 = e.MarketDepth.Ask[4].Volume;


    data = AskPrice0 + AskPrice1 + AskPrice2 + AskPrice3 + AskPrice4;

    Plot0.Set(data);

    I ran this on the Simulator and it ran fine for about 1 1/2 hours, then I get this error message, "Error on calling "OnMarketDepth" 'MyFileName': 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 in the chart."

    I usually see this error if I forget to put this in the beginning of my script, " if(CurrentBar < xx)return;" But when this is the problem, the script will not work at all until I insert the CurrentBar line. My code executes fine, then stops suddenly. If I open up the Indicator window of the chart and click OK, then it starts working again, but at some point later, errors again.

    So it appears there is a problem processing the data a some point. I added a Print statement to see if anything unusual showed up, but when the error occurs, it just prints the error and the data before that looked normal. Any suggestions as to how I can stop this error from occuring?

    Thanks,

    Safetrading

    #2
    You're asking to plot 5 levels of depth, and you're probably getting that error at a time when there aren't 5 levels of depth to plot.

    Comment

    Latest Posts

    Collapse

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