Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-Timeframe use in a Strategy

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

    #16
    imported post

    Please post your strategy, so we can take a look.

    Thanks

    Comment


      #17
      imported post


      Here it is:

      #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>

      /// Enter the description of your strategy here

      ///</summary>

      [Description(
      "Enter the description of your strategy here")]

      [Gui.Design.DisplayName(
      "Pivot MA using Multi Timeframes")]

      publicclass PivotMAMultiTimeFrame : Strategy

      {

      #region Variables

      // Wizard generated variables

      privateint longMAPeriods = 3; // Default setting for LongMAPeriods

      privateint shortMAPeriods = 1; // Default setting for ShortMAPeriods

      privateint trailingStop = 10; // Default setting for TrailingStop

      // 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()

      {

      SetTrailStop(
      "", CalculationMode.Ticks, TrailingStop, false);

      Add(PeriodType.Minute,
      5);

      CalculateOnBarClose =
      true;

      }

      ///<summary>

      /// Called on each bar update event (incoming tick)

      ///</summary>

      protectedoverridevoid OnBarUpdate()

      {

      int LTFLong = 0;

      int STFLong =0;

      int TimeCheck = 0;

      Print(BarsInProgress.ToString() +
      " " + Time[0]);



      // Condition set Long

      if (Close[0] > EdsPivotSMA(LongMAPeriods, ShortMAPeriods).LongSMA[0]

      && Close[
      0] > EdsPivotSMA(LongMAPeriods, ShortMAPeriods).ShortSMA[0]

      && EdsPivotSMA(LongMAPeriods, ShortMAPeriods).ShortSMA[
      0] > EdsPivotSMA(LongMAPeriods, ShortMAPeriods).LongSMA[0])

      LTFLong =
      1;



      if (Closes[1][0] > EdsPivotSMA(BarsArray[1],LongMAPeriods,ShortMAPeriods).LongSMA[0]

      && Closes[
      1][0] > EdsPivotSMA(BarsArray[1],LongMAPeriods, ShortMAPeriods).ShortSMA[0]

      && EdsPivotSMA(BarsArray[
      1],LongMAPeriods, ShortMAPeriods).ShortSMA[0] >

      EdsPivotSMA(BarsArray[
      1],LongMAPeriods, ShortMAPeriods).LongSMA[0])

      STFLong =
      1;



      if (ToTime(Time[0]) > ToTime(9, 30, 0) && ToTime(Time[0]) <= ToTime(15, 30, 0))

      TimeCheck =
      1;

      else

      TimeCheck =
      0;



      {

      if(LTFLong == 1 )

      if(STFLong == 1)

      if(TimeCheck == 1)

      EnterLongLimit(DefaultQuantity, Close[
      0], "Buy Long");

      ExitShortLimit(Close[
      0], "Cover Short", "");

      Print(BarsInProgress.ToString() +
      " " + Time[0]);

      }

      // Condition set Short

      if (Close[0] < EdsPivotSMA(LongMAPeriods, ShortMAPeriods).LongSMA[0]

      && Close[
      0] < EdsPivotSMA(LongMAPeriods, ShortMAPeriods).ShortSMA[0]

      && EdsPivotSMA(LongMAPeriods, ShortMAPeriods).ShortSMA[
      0] < EdsPivotSMA(LongMAPeriods, ShortMAPeriods).LongSMA[0])



      if (Closes[1][0] < EdsPivotSMA(BarsArray[1],LongMAPeriods,ShortMAPeriods).LongSMA[0]

      && Closes[
      1][0] < EdsPivotSMA(BarsArray[1],LongMAPeriods, ShortMAPeriods).ShortSMA[0]

      && EdsPivotSMA(BarsArray[
      1],LongMAPeriods, ShortMAPeriods).ShortSMA[0] <

      EdsPivotSMA(BarsArray[
      1],LongMAPeriods, ShortMAPeriods).LongSMA[0])



      if (ToTime(Time[0]) > ToTime(9, 30, 0)

      && ToTime(Time[
      0]) <= ToTime(15, 30, 0))

      {

      ExitLongLimit(Close[
      0], "Exit Long", "Buy Long");

      EnterShortLimit(DefaultQuantity, Close[
      0], "Enter Short");

      }



      }

      #region Properties

      [Description(
      "")]

      [Category(
      "Parameters")]

      publicint LongMAPeriods

      {

      get { return longMAPeriods; }

      set { longMAPeriods = Math.Max(1, value); }

      }

      [Description(
      "")]

      [Category(
      "Parameters")]

      publicint ShortMAPeriods

      {

      get { return shortMAPeriods; }

      set { shortMAPeriods = Math.Max(1, value); }

      }

      [Description(
      "")]

      [Category(
      "Parameters")]

      publicint TrailingStop

      {

      get { return trailingStop; }

      set { trailingStop = Math.Max(1, value); }

      }

      #endregion

      }

      }

      Comment


        #18
        imported post

        Guys,

        I've solved the double reading on the 1/2 hour but still am getting the error message.

        Comment


          #19
          imported post

          The problem is that your have 2 series on the same instrument. You then only can place orders on the frist series for this instrument.

          You need to do something like:
          Code:
          if (BarsInProgress != 0)
           return;
          ... since order placements on BarsInProgress==1 will throw the error you saw.

          Comment


            #20
            imported post

            Yes this solved the error problem. Based on your comment that I can only place orders on the first series that I'll have to modify my program as I want to place orders based on the shorter time frame.

            One other question; when the Analyzer runs and determines the entry and exit points, does it use the tick data that I have stored for the instrument or what data does it use.

            thx,

            Fred

            Comment


              #21
              imported post

              What do you mean by "tick data stored"?

              There are three different potential data sources:
              - historical tick data downloaded from a provider like eSignal: it will be used provided you have a "tick based" timeframe
              - historical tick data you recorded as you had a chart running (Tools->Options->Data->Store realtime bar data checked): it will be used provided you have a "tick based" or "minute based" timeframe
              - data your recorded using the market replay recorder (Tools->Options->Data->Run market replay recorder checked): will not be used for backtesting

              Comment


                #22
                imported post

                I meant the tick data that I've downloaded and stored from my data supplier in real time.

                Comment


                  #23
                  imported post

                  So option (a) -> will be used for your "tick timeframe" strategy

                  Comment


                    #24
                    Can Multiple-Timeframes also be used within an indicator, so that for example 1m and 5m timeframes are both used in the calculation?

                    Comment


                      #25
                      Not possible

                      Comment


                        #26
                        Although it is possible in a strategy to have mixed time frames and instruments. Additional information can be found at the link below.

                        RayNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by traderqz, Yesterday, 04:32 PM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by f.saeidi, Today, 05:56 AM
                        1 response
                        3 views
                        0 likes
                        Last Post Jltarrau  
                        Started by Jltarrau, Today, 05:57 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post Jltarrau  
                        Started by Stanfillirenfro, Yesterday, 09:19 AM
                        7 responses
                        51 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by TraderCro, 04-12-2024, 11:36 AM
                        4 responses
                        70 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Working...
                        X