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

SampleOnOrderUpdate - BarsRequiredToTrade

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

    SampleOnOrderUpdate - BarsRequiredToTrade

    Hello,
    I get the following error message by the attached strategy aa01OnOrderUpdate, derived from strategy SampleOnOrderUpdate posted on the help on line:
    “Strategy 'aa01OnOrderUpdate': Error on calling 'OnBarUpdate' method on bar 0: 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.” and it does not trigger any trade.
    I do not understand why the BarsRequiredToTrade = 20 set in the State.SetDefaults does not satisfy the minimum 5 bars requested mentioned in the error messages. Please could you help to solve this error message?
    Thank you.

    aa01OnOrderUpdate.zip

    #2
    Hello guidoisot,

    The error indicates an invalid index was used.

    Below is a link to a forum post that discusses invalid indexes.
    Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:


    What is the specific line of code that is causing the error?


    BarsRequiredToTrade ignores order submissions before there are that many bars. This does not prevent invalid indexes used from causing an indexing error.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you, for your support.
      I have added this filter
      if(Close[0]>Close[Math.Min(CurrentBar,1)])
      and now it works.
      This strategy works only in real time, so I understand it is not possible to backtest it.
      Is market replay the only (quicker) alternative to evaluating it in real time?
      Another question I would have is whether it is possible to link the stoploss exit to an indicator or to another parameter, for example: to set an exit Long when last swing low is crossed below, or to set an exit Long when as a trailing at the low of prior bar?
      Thx.

      Comment


        #4
        Hello guidoisot,

        Likely, you were using a barsAgo value that is invalid on the first bar (High[1]).

        I'm not seeing anything in this script that would prevent the script from placing orders historically.


        Backtesting in the Strategy Analyzer would be faster than Market Replay, even with 1 tick granularity for accuracy in fill prices.

        Yes, the limit price or stop price accepts a double. This could be the double returned by an indicator.

        For example:

        if (CurrentBar > 1 && SMA(14)[1] < GetCurrentBid())
        {
        ExitLongStopMarket(SMA(14)[1]);
        }
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rocketman7, Today, 02:12 AM
        1 response
        16 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by briansaul, Today, 05:31 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by PaulMohn, Today, 03:49 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by frslvr, 04-11-2024, 07:26 AM
        6 responses
        106 views
        1 like
        Last Post NinjaTrader_BrandonH  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        6 responses
        26 views
        0 likes
        Last Post trilliantrader  
        Working...
        X