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

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.
      JimNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by javier.filgueira, Today, 03:07 PM
      0 responses
      29 views
      0 likes
      Last Post javier.filgueira  
      Started by cassb, Today, 03:09 PM
      0 responses
      28 views
      0 likes
      Last Post cassb
      by cassb
       
      Started by ChasK, Today, 10:03 AM
      3 responses
      43 views
      0 likes
      Last Post Lancer
      by Lancer
       
      Started by UltraNIX, Today, 01:07 PM
      3 responses
      37 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Started by reks13, Today, 11:14 AM
      1 response
      36 views
      0 likes
      Last Post NinjaTrader_PaulH  
      Working...
      X