Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error enabling strategy in particular instrument timeframe

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

    Error enabling strategy in particular instrument timeframe

    Hello, I am have developed a strategy and I am trying to enable on sim account to trade forex.

    It enables fine on daily and intradaily on all instruments I have tried - except for EURUSD in minute intervals where I get the folliowing error in the logs:

    " Error on calling 'OnBarUpdate' method on bar 643: You are accessing an index with an index that is invalid since it is out-of-range.I.E.accesing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart "

    It enables on EURUSD daily.

    Any help is appreciated.

    #2
    Problem solved.

    I have located the code line creating the error.

    if (SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency > 0) qty = 1;

    Checking for winning trade after submitting an ExitLong() order causes an error.

    Comment


      #3
      Hello im1`97,

      Welcome to the forums! I am also happy to hear the matter is resolved.

      An order method will take time to submit the order and receive an execution, so the trade likely would not be complete immediately after calling the Exit method in OnBarUpdate. The code could be protected by checking if SystemPerformance.AllTrades.Count is greater or equal to 1 so the reference will be made when the trade exists in the collection.

      If you have any other NinjaScript related inquiries, please don't hesitate to open a new thread.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, Today, 06:46 AM
      0 responses
      9 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, Yesterday, 05:21 PM
      0 responses
      14 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      15 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      82 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      48 views
      0 likes
      Last Post PaulMohn  
      Working...
      X