Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi Timeframe Strategy

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

    Multi Timeframe Strategy

    Hi,

    I am trying to code an intraday strategy which works on minute bars. However, part of the logic requires the value of a 5 day MA to be accessed.

    In initiate, I have this code where MovAvg has already been declared under variables.

    Code:
    Add(PeriodType.Day, 1);
    			
    MovAvg = SMA(BarsArray[1], 5);
    Add(MovAvg);
    However, this causes problems as the strategy will not even initialize in Strategy Analyzer. Do you have any suggestions on how I should go about this? Or would I need to code calculations that record closing prices at every close and manually calculate a moving average?

    Thanks!

    #2
    Hello wuilengh,

    You would not want to access the "BarsArray" object inside of the Initialize() method. See our help guide at the following link for more information.
    http://www.ninjatrader.com/support/h...?barsarray.htm

    You would want to calculate the SMA of the 5 day period manually inside of OnBarUpdate(). If you want to plot the value of the different time frame of the SMA you would have to use the Strategy Plot method to plot the value of the SMA. You may view our thread a the following link for an example of this.
    When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability
    JCNinjaTrader Customer Service

    Comment


      #3
      Hi JC,

      Just a quick follow up question - let's say I've done Add(PeriodType.Day, 1) in the Initialize() method of my strategy which has a primary series of 1 minute bars.

      If I now wanted a 20-day SMA based on the daily bars, what would be the best way to go about it? In OnBarUpdate() I am now trying to Print(SMA(BarsArray[1], 20)). The problem I am having now is that the strategy is not back-loading sufficient daily bars and I am getting the following error:

      **NT** Error on calling 'OnBarUpdate' method for strategy 'Strategy/46798e28dfb14e44884895466fc9204a': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

      Setting the min bars required high enough (on 1 min granularity) to capture enough daily bars seems to cause any backtesting to fail without any error message. Is there a better way around this problem?

      Thanks again!

      Comment


        #4
        Hello wuilengh,

        You would want to check to make sure that you have enough bars of data before you start calculating your Strategy by using CurrentBars so you do not run into that issue of accessing an index value that is invalid. Here is a link to our Help Guide that shows how to check CurrentBars.
        JCNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, Yesterday, 10:06 AM
        0 responses
        20 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        18 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        14 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        9 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        40 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X