Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnStateChange Error

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

    OnStateChange Error

    I'm getting the following error when trying to run a backtest:
    Error on calling 'OnStateChange' method: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    The Strategy using what the ATR was on the previous bar (BarsAgo = 1) to determine Target and Stop orders.
    It also is looking at the close of 2 Bars ago and comparing to the close of the previous bar (BarsAgo = 1).

    Minimum bars to trade is set to 20, which should be/ is fine, as ATR period is set below that. Tried multiple values, that doesn't seem to be the culprit.

    #2
    Hello 963robo,

    Thanks for your post.

    This error message indicates that you are trying to access a BarsAgo value that is not valid. A more simple example using one series would be on bar 5 you check for 6 BarsAgo. There are not yet 6 bars so the CurrentBar minus 6 would be a negative number or a non-existent bar.

    A CurrentBar check could be used in your indicator's logic to ensure that a certain number of bars have processed before the indicator begins calculation.​

    See the help guide documentation below for more information.

    CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
    CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
    Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DeskTroll, Today, 12:09 PM
    3 responses
    23 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by Pabulon, 12-02-2024, 03:42 PM
    14 responses
    90 views
    0 likes
    Last Post Pabulon
    by Pabulon
     
    Started by tfa2806trader, Today, 12:04 PM
    10 responses
    25 views
    0 likes
    Last Post tfa2806trader  
    Started by trdninstyle, 11-26-2024, 12:23 PM
    62 responses
    186 views
    0 likes
    Last Post trdninstyle  
    Started by lorien, 08-08-2021, 07:33 AM
    12 responses
    722 views
    0 likes
    Last Post AndyM871  
    Working...
    X