Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtesting with two different timeframes

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

    Backtesting with two different timeframes

    Hello,

    I wish to label the cross point between two MAs with a line or a dot.
    When using the 15 min timeframe, the label moves to the close of the bar.
    I realized that only real time will do the tick by tick label. However, is it possible to use, for example, the bar-close from the 1 min timeframe to label the cross point on the 15 min timeframe?

    Tnx

    bkool

    #2
    Hi bkool, Welcome to the NinjaTrader support forums!

    You could set your indicator to CalculateOnBarClose = false, as this would then update the 15 min bar intrabar. Please see also this link - http://www.ninjatrader-support.com/H...BarClose1.html

    For building a strategy, you could create a MultiTime strategy using the 15 min and a smaller frame - http://www.ninjatrader-support.com/H...struments.html

    Please also review this reference sample with demonstration code - http://www.ninjatrader-support2.com/...ead.php?t=6652
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks Bertrand.
      The reference sample is indeed helpful.
      In this sample, the reference to the secondary bar series is put as the initial digit - EnterLong(1, 1, "Long: 1min");
      Where do you add the reference using the DrawLine syntax?

      bkool

      Comment


        #4
        You cannot draw on the secondary series because what you see on the chart is only the primary series.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I want to draw a line on the primary (say 15 min) chart using the bars series of the secondary (1 min). If I use the 15 min bars the line is drawn at the close of the bar, while the event (say MA cross) happened in the middle of the 15 min bar.

          Comment


            #6
            bkool,

            See this reference sample for plotting from a strategy: http://www.ninjatrader-support2.com/...ead.php?t=6651
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Couldn't figure it out.
              This is the code - may be someone else could help.

              Many thnaks.
              --------------------------------------------------------------
              protectedoverridevoid Initialize()
              {
              Add(CCI(
              14));
              CalculateOnBarClose =
              false;
              }
              protectedoverridevoid OnBarUpdate()
              {
              if (CrossAbove(CCI(14), 0, 1))
              {
              DrawLine(
              "My line" + CurrentBar, 6, Median[0], 0, Median[0], Color.Blue);
              }
              if (CrossBelow(CCI(14), 0, 1))
              {
              DrawLine(
              "My line" + CurrentBar, 6, Median[0], 0, Median[0], Color.DarkTurquoise);
              }
              }
              ----------------------------------------------------------------------

              Comment


                #8
                Hi bkool, please use a unique tag id for each drawing object, for example this OnBarUpdate() should work -

                Code:
                [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] OnBarUpdate()
                {
                [/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] (CrossAbove(CCI([/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]), [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2], [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]))
                DrawLine([/SIZE][/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000]"My line1"[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] + CurrentBar, [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]6[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2], Median[[/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]], [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2], Median[[/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]], Color.Blue);
                [/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] (CrossBelow(CCI([/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]), [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2], [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]))
                DrawLine([/SIZE][/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000]"My line2"[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] + CurrentBar, [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]6[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2], Median[[/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]], [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2], Median[[/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]], Color.DarkTurquoise);
                }
                [/SIZE][/SIZE]

                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Well,
                  I think I got it eventually; thanks Bertrand - any comments?

                  protected override void Initialize()
                  {
                  Add(CCI(14));
                  Add(PeriodType.Minute, 1);
                  CalculateOnBarClose = false;
                  }
                  protected override void OnBarUpdate()
                  {
                  if (BarsInProgress == 0)
                  if (CrossAbove(CCI(14), 0, 1))
                  {
                  double CCIXa = Closes[1][0];
                  DrawLine("My line1" + CurrentBar, 6, CCIXa, 0, CCIXa, Color.Blue);
                  Print("The current CCI crossabove 0 value is " + CCIXa.ToString()); // check values

                  }

                  if (BarsInProgress == 0)
                  if (CrossBelow(CCI(14), 0, 1))
                  {
                  double CCIXb = Closes[1][0];
                  DrawLine("My line2" + CurrentBar, 6, CCIXb, 0, CCIXb, Color.Green);
                  Print("The current CCI crossbelow value is " + CCIXb.ToString()); // check values:

                  }

                  }

                  Comment


                    #10
                    Great you got it working bkool! Do you get the expected results running it realtime?
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Thansk Bertrand.

                      It works fine on real time - I tested it on a primary chart of 15 min, where the secondary barsarray is of 1 min. Also, on a 5 min, where the secondary barsarray is of 5 seconds. The latter, however, is CPU intensive. Is there a way to make it less intensive by limiting the amount of 5 sec data??

                      bkool

                      Comment


                        #12
                        Hi bkool, you limit how much data is loaded in the 'Format Data Series' window, look for the 'DaysBack' setting.
                        BertrandNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Perr0Grande, Today, 08:16 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post Perr0Grande  
                        Started by elderan, Today, 08:03 PM
                        0 responses
                        3 views
                        0 likes
                        Last Post elderan
                        by elderan
                         
                        Started by algospoke, Today, 06:40 PM
                        0 responses
                        10 views
                        0 likes
                        Last Post algospoke  
                        Started by maybeimnotrader, Today, 05:46 PM
                        0 responses
                        9 views
                        0 likes
                        Last Post maybeimnotrader  
                        Started by quantismo, Today, 05:13 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post quantismo  
                        Working...
                        X