Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing an index with a value that is invalid

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

    Accessing an index with a value that is invalid

    So i ran this strategy in market play back just 2 days ago and everything was working fine. Since then the only thing i've done is downloaded more days of market data. Anything you can think of that would cause this error now when i try to start the strategy in market replay? I haven't changed any of the code at all.

    Click image for larger version

Name:	image.png
Views:	38
Size:	4.8 KB
ID:	1306564

    #2
    Here is a bit more information... this is what i'm finding on debugging

    Click image for larger version  Name:	image.png Views:	0 Size:	14.2 KB ID:	1306566

    Here is the code snippets

    Code:
    protected override void OnBarUpdate()
    {
    
    
    if (CurrentBars[0] < 2 && CurrentBar >= ema.Period/*|| CurrentBars[1] < 2*/)
    return;
    
    double emaValue = ema[0];
    
    
    //Entry Criteria for Longs
    bool isFirstCandleRed = Close[2] < Open[2]; // Check if the first candle is red[/COLOR]
    ​
    I am getting the error on the last line of code that there for the isFirstCandleRed. ​I dont understand why the strategy worked yesterday though.

    The strategy is basically trying to look at the prior two candles, and then entry is on the third candle.
    Last edited by sofortune; 06-08-2024, 12:15 PM.

    Comment


      #3
      Hello sofortune,

      The condition you have to return looks strange, if you need 2 barsago your condition should look like this assuming you used AddDataSeries to add a secondary series:

      if (CurrentBars[0] < 2 | CurrentBars[1] < 2)
      return;

      That makes sure both series have at least 2 bars which would be needed because the code you are using will be executed for both series. If you did not use AddDataSeries and this is a single series script it would be:

      if(CurrentBar < 2) return; ​

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      44 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
      65 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 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