Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

multi-time frame strategy problem

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

    multi-time frame strategy problem

    Hi all,

    I am just beginning to construct a multi time frame strategy and am having some trouble starting off.

    I am just looking to set a series of doubles for certain time periods but no long position is opened.

    As is usual, it is probably a simple error, but would appreciate any advice as to how to obtain the required trades so they can be utilised for the strategy.

    The required code is written below.

    PHP Code:
    // 
    // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Strategy;
    #endregion
    
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// This is a sample multi-time frame strategy.
        /// </summary>
        [Description("This is a sample multi-time frame strategy.")]
        public class SampleMultiTimeFrame_day : Strategy
        {
            #region Variables
            // Wizard generated variables
            // User defined variables (add any user defined variables below)
            #endregion
    
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                // Add a 5 minute Bars object to the strategy
                Add(PeriodType.Day, 1);
                
                // Add a 15 minute Bars object to the strategy
                Add(PeriodType.Week, 1);
                
                // Note: Bars are added to the BarsArray and can be accessed via an index value
                // E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above
                
                // Add simple moving averages to the chart for display
                // This only displays the SMA's for the primary Bars object on the chart
                Add(SMA(5));
                Add(SMA(50));
                
                CalculateOnBarClose = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
                // We only want to process events on our primary Bars object (index = 0) which is set when adding
                // the strategy to a chart
                if (BarsInProgress != 0)
                    return;
                
                // Checks  if the 5 period SMA is above the 50 period SMA on both the 5 and 15 minute time frames
                if (SMA(BarsArray[1], 5)[0] > SMA(BarsArray[1], 50)[0] && SMA(BarsArray[2], 5)[0] > SMA(BarsArray[2], 50)[0])
                {
                    // Checks for a cross above condition of the 5 and 50 period SMA on the primary Bars object and enters long
                    if (CrossAbove(SMA(5), SMA(50), 1))
                        EnterLong(1000, "SMA");
                }
                
                // Checks for a cross below condition of the 5 and 15 period SMA on the 15 minute time frame and exits long
                if (CrossBelow(SMA(BarsArray[2], 5), SMA(BarsArray[2], 50), 1))
                    ExitLong(1000);
            }
    
            #region Properties
            #endregion
        }
    } 
    
    Last edited by mfmsonic; 12-17-2009, 07:08 AM.

    #2
    mfmsonic,

    Please ensure you have enough bars loaded. You need at least 20 on each bar series. 20 on weekly series would require a lot of days back to load.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_Josh,
      Thank you for your reply. The bars are long enough from 1962 to 2009. Still no trades. Here are the snapshot from my backtesting. Please check it.
      Attached Files

      Comment


        #4
        You will then need to debug your code with Print() statements and TraceOrders = true.


        Josh P.NinjaTrader Customer Service

        Comment


          #5
          It might be an issue with update sequence. Try using the value 2 for the lookBackPeriod in the CrossAbove, Below tests.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          648 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          573 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          575 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X