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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    43 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    68 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    56 views
    0 likes
    Last Post CarlTrading  
    Working...
    X