Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multitimeframe strategy

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

    Multitimeframe strategy

    Hi, I am devoloping an estrategy that make entrymarket position long/short in 30min bars, according MACD daily position.

    If Macd daily fast period value is below 0 it only take short position.

    If Macd daily fast period value is above 0 it only take long position.

    I try the estrategy on charts and it makes trades during a period but suddenly it doesn't works for the rest of the chart

    I try it on AIG chart from january the first, and the mistake appears on may the nineth, is the first day daily macd falls below 0, and appears an stoplongentry order on the chart that coincide with 16:00bar max of the nineth.

    Here I let you the code, do you see what is going wrong?




    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    ///<summary>
    /// Enter the description of your strategy here
    ///</summary>
    [Description("Enter the description of your strategy here")]
    publicclass RotRangH : Strategy
    {
    #region Variables
    // Wizard generated variables
    privatedouble stoploss = 0.030; // Default setting for Stoploss
    // 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>
    protectedoverridevoid Initialize()
    {
    Add (PeriodType.Day, 1);

    SetStopLoss("", CalculationMode.Percent, Stoploss, false);
    CalculateOnBarClose = true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    // Checks if the macd daily fast period is above 0 and time in 30min bars is 16:00,
    //then gives variable0 value= high 16:00(30minbar) and enter a stop longposition at value0
    if (MACD(BarsArray[1], 12, 26, 9)[0] > 0 && ToTime(Time[0]) == 160000)
    Variable0 = High[0] + 1*TickSize;
    EnterLongStop(DefaultQuantity, Variable0, "");

    // Checks if the macd daily fast period is below 0 and time in 30min bars is 16:00,
    //then gives variable1 value= Low 16:00(30minbar) and enter a stop shortposition at value1
    if (MACD(BarsArray[1], 12, 26, 9)[0] < 0 && ToTime(Time[0]) == 160000)
    Variable1 = Low[0] - 1*TickSize;
    EnterShortStop(DefaultQuantity, Variable1, "");


    }
    Last edited by julen; 09-12-2008, 06:18 AM.

    #2
    I am not sure what you exactly you mean, but first try this. Swap the bars objects. So run your strategy on a daily chart and change your Add(PeriodType.Day, 1) to Add(PeriodType.Minute, 30). Be sure you change up the logic inside to reflect this change too.

    Reason to make this change is to ensure that the bar sequence fires correctly during backtesting.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      First Of all thanks for your reply, and I understand what you propose, but I will try to explain you with my terrible english what I'm trying, I want to enter in market long or short if 30minbar that finishes at 16:00( Spanish hour, I think it's 10AM in USA) High or Low is crossed. I introduce a filter: If daily Macd Fast line is above 0, enter long if 30minbar High is broken;
      If daily Macd Fast line is below 0, enter short if 30minbar Low is crossed.

      I will try like you propose, but how can I refer 30minbar High or Low? is this correct?

      High(BarsArray[1])[0]
      Low(BarsArray[1])[0]

      And to tell that 30minbar That I'm refering is that wich ends at 16:00?

      Totime(BarsArray[1], Time[0]) == 160000

      or better:

      BarTimer(BarsArray[1])[0] == 160000

      Thank you very much for your attention.

      Comment


        #4
        Maybe this reference sample can provide some guidance.

        RayNinjaTrader Customer Service

        Comment


          #5
          muti-time frame

          Originally posted by julen View Post
          First Of all thanks for your reply, and I understand what you propose, but I will try to explain you with my terrible english what I'm trying, I want to enter in market long or short if 30minbar that finishes at 16:00( Spanish hour, I think it's 10AM in USA) High or Low is crossed. I introduce a filter: If daily Macd Fast line is above 0, enter long if 30minbar High is broken;
          If daily Macd Fast line is below 0, enter short if 30minbar Low is crossed.

          I will try like you propose, but how can I refer 30minbar High or Low? is this correct?

          High(BarsArray[1])[0]
          Low(BarsArray[1])[0]

          And to tell that 30minbar That I'm refering is that wich ends at 16:00?

          Totime(BarsArray[1], Time[0]) == 160000

          or better:

          BarTimer(BarsArray[1])[0] == 160000

          Thank you very much for your attention.
          Hi Julien,
          I think ninja cannot handle more than one time frame. Have you found a way to go round this problem....they promised it will be sorted in NT7.
          If you are ahead of the game....let us in.
          Cheers.

          Comment


            #6
            Hello boboinuk,

            Multi time frame strategies are supported. Please see the link below.

            Comment

            Latest Posts

            Collapse

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