Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 algospoke, Yesterday, 06:40 PM
    2 responses
    22 views
    0 likes
    Last Post algospoke  
    Started by ghoul, Today, 06:02 PM
    3 responses
    14 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    45 views
    0 likes
    Last Post jeronymite  
    Started by Barry Milan, Yesterday, 10:35 PM
    7 responses
    21 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by AttiM, 02-14-2024, 05:20 PM
    10 responses
    181 views
    0 likes
    Last Post jeronymite  
    Working...
    X