• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Change to multitimeframe strategies in NT?

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

    Change to multitimeframe strategies in NT?

    Hi - I have several strategies that use multiple timeframes comparing minute closes to daily averages...
    i.e.

    if
    Close[0] < AverageOfSameTickerDaily[0] then Sell Short

    In a recent update of ninjatrader using the longer timeframe with a value of [0] seems to throw the following error, even when using strategy builder:

    "Strategy 'z02newWork': Error on calling 'OnBarUpdate' method on bar 90: 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."

    Was there a recent (last few months) change that is impacting this?

    #2
    Hello RandanAL,

    There were no changes that should affect calling a series that I am aware of.

    One common case where you would see this error relates to data changing over time and what data is available for the instruments being used. An example would be a situation where the script runs normally until a specific point in time when it stops working. This may relate to data availability for one or more of the instruments and not checking if the data is available in code.

    Do you currently have a condition similar to the following checking for data?
    Code:
    if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;

    If you do not the code would be prone to these type of errors. If you otherwise do have a condition like this you will very likely need to use Prints to identify what specifically is throwing the error. An easy way to locate the error would be to comment out the existing logic and then just print each object by its self and then find when you see the error.
    Code:
    Print( AverageOfSameTickerDaily[0]);
    That type of test will at least tell you what series the problem relates to so we can add more relevant prints for that series.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick response - always super helpful! This seems to work out the issue when using the ninjascript editor:

      Code:

      if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
      Is there a way to have this work in strategy builder - adjusting bars required to trade doesn't seem to do the trick...
      Worst case scenario I can do it in ninjascript editor but it is nice to be able to quickly iterate in strategy builder before jumping into the code.



      Comment


        #4
        Hello RandanAL,

        The builder should automatically add this type of syntax however it does it slightly differently due to not being able to use the secondary series logically. You should see the following generated when using a Secondary series along with any BarsAgo:

        Code:
            if (BarsInProgress != 0) 
                        return;
        
        if (CurrentBars[0] < 0
        || CurrentBars[1] < 30)
                        return;
        
        // Set 1
        if (Close[0] == Closes[1][30])
        {
        }

        If you are seeing that this syntax is not being generated or fails in the builder we would likely want to investigate that in more detail. If that is with a Custom indicator it may be just because of that use case. Please also try using the SMA in the same scenario to see if you get an error, if so I can report the steps involving the stock indicator for review.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Yes - I've now confirmed that the builder isn't creating any similar code. Seems like maybe my builder has a bug or something.

          The below is what the code is returning on a pretty simple strategy.
          EMA1 is just a plain 15 Day EMA of the default data series but on a daily basis. Basically selling short if EMA is above 65, closing if below 35. Don't short if above the EMA and close if the position rises above it while active.



          protected override void OnBarUpdate()
          {
          if (BarsInProgress != 0)
          return;

          if (CurrentBars[0] < 1)
          return;

          // Set 1
          if ((RSI1.Avg[0] > RSIsellHigh)
          && (Close[0] < EMA1[0]))
          {
          EnterShort(Convert.ToInt32(DefaultQuantity), "");
          }


          // Set 2
          if ((RSI1.Avg[0] < RSIbuyHigh)
          || (Close[0] > EMA1[0]))
          {
          ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
          }




          Comment


            #6
            Hello RandanAL,

            Would you mind exporting this strategy as it is now and attaching it for me to review?

            https://ninjatrader.com/support/help...tAsSourceFiles

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by superkolleech, Today, 12:46 AM
            1 response
            12 views
            0 likes
            Last Post MojoJojo  
            Started by davidwade, Today, 02:51 AM
            0 responses
            3 views
            0 likes
            Last Post davidwade  
            Started by aviat72, 04-26-2020, 09:41 PM
            10 responses
            92 views
            0 likes
            Last Post kissandfly  
            Started by healthooa, Today, 01:28 AM
            0 responses
            8 views
            0 likes
            Last Post healthooa  
            Started by harjinderjit, Yesterday, 08:24 PM
            0 responses
            20 views
            0 likes
            Last Post harjinderjit  
            Working...
            X