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

multitimeframe question

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

    multitimeframe question

    Hi,

    I was reading the following sample script

    Question : Does this example have two time frames namely 5 minutes and 15 minute time frames

    or

    are there three time frames in the example below ?



    copy of script is here below


    SampleMultiTimeFrameOrders : Strategy

    //
    // Copyright (C) 2008, 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>
    /// Reference sample demonstrating how to submit orders to different bars arrays.
    /// </summary>
    [Description("Reference sample demonstrating how to submit orders to different bars arrays.")]
    public class SampleMultiTimeFrameOrders : 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.Minute, 5);

    // Add a 15 minute Bars object to the strategy
    Add(PeriodType.Minute, 15);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    /* OnBarUpdate() method will execute this portion of the code when incoming ticks are on the
    primary bar object. */
    if (BarsInProgress == 1)
    {
    /* Checks if the 5 period SMA is decreasing in the secondary bar series (5min) and if it is below the 10
    period SMA in the tertiary bar series (15min). */
    if (SMA(5)[0] < SMA(5)[1] && SMA(5)[0] < SMA(BarsArray[2], 10)[0])
    {
    /* Exit the long position entered from the 15min bar object on a more granular time period.
    This allows for more control in the management of your positions and can be used to improve
    exit timing of your trades. */
    ExitLong("Exit Long from 5min", "Enter Long from 15min");
    }
    }

    /* OnBarUpdate() method will execute this portion of the code when incoming ticks are on the
    tertiary bar object (15min). */
    if (BarsInProgress == 2)
    {
    // Checks if the 25 period SMA is greater than the 50 period SMA on the 15min.
    if (SMA(25)[0] > SMA(50)[0])
    {
    /* Enter long for 1 contract on the 15min bar object based on the barsInProgress parameter.
    A value of 0=primary bars, 1=secondary bars, 2=tertiary bars */
    EnterLong(2, 1, "Enter Long from 15min");
    }
    }
    }

    #region Properties
    #endregion
    }
    }

    #2
    rjngh2005,

    There will be 3 total series. The primary series is the one that the strategy is applied to. Then the strategy adds two more in Initialize().

    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      If you want 3 time frames in the script....is the order important

      say for example I have 5 minutes , 15 minutes, 30 minute time frames
      is it important that the primary time frame is 5 minute or 30 minutes ?


      second question

      in the code below

      if (BarsInProgress == 1)
      {
      /* Checks if the 5 period SMA is decreasing in the secondary bar series (5min) and if it is below the 10
      period SMA in the tertiary bar series (15min). */
      if (SMA(5)[0] < SMA(5)[1] && SMA(5)[0] < SMA(BarsArray[2], 10)[0])
      {
      /* Exit the long position entered from the 15min bar object on a more granular time period.
      This allows for more control in the management of your positions and can be used to improve
      exit timing of your trades. */
      ExitLong("Exit Long from 5min", "Enter Long from 15min");
      }
      }


      in particular the following code
      (SMA(5)[0] < SMA(5)[1] && SMA(5)[0] < SMA(BarsArray[2], 10)[0])

      since we are in the Secondary time frame section
      does SMA(5)[0] refer to the primary, secondary or tertiary time frame ?

      Comment


        #4
        The order was important in NinjaTrader 6.5, but in 7 you can add series in any order.

        BarsInProgress defines the context of updates. If you use this with BIP = 1
        SMA(5)[0] - That's the SMA for the secondary series - the first one added in Initialize()

        However, SMA(BarsArray[2], 10)[0])
        Even though you access within BIP1, since you're accessing a multi-time frame value (BarsArray[2]), that will be the tertiary series - the second one added.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          The order was important in NinjaTrader 6.5, but in 7 you can add series in any order.
          Since I am working with NT 6.5
          could you explain more about the order for Primary, secondary, tertiary time frames please...?

          Comment


            #6
            In 6.5, added series interval should be smaller than the primary. If you're working with 5, 15, and 30 minute it should be:
            Primary = 30
            Secondary = 15
            Tertiary = 5.

            Unless you have a specific need to continue with 6.5, I suggest using NT7, especially for multiseries scripts.
            Last edited by NinjaTrader_RyanM1; 06-15-2011, 11:38 AM.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by WHICKED, Today, 12:45 PM
            2 responses
            17 views
            0 likes
            Last Post WHICKED
            by WHICKED
             
            Started by GussJ, 03-04-2020, 03:11 PM
            15 responses
            3,272 views
            0 likes
            Last Post xiinteractive  
            Started by Tim-c, Today, 02:10 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Taddypole, Today, 02:47 PM
            0 responses
            2 views
            0 likes
            Last Post Taddypole  
            Started by chbruno, 04-24-2024, 04:10 PM
            4 responses
            51 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Working...
            X