Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entries in Backtesting

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

    Entries in Backtesting

    I have two questions regarding back testing in NT.

    1. I have a simple strategy that buys ES on the open. But on the backtesting for example if I use 20 min. charts, the position is open on the second bar. I want to open the position if the condition is met at the opening price on the first bar in the regular trading hours. I disabled the calculate on bar close in my strategy but that does not change anything.

    2. When the position is open if it is stopped during the day or after some days, NT immediately opens new position. How do I disable that. For example if the position is stopped or taken profit I want to open new position only when another condition is met, but NT opens another position immediately.

    Thanks

    #2
    Hello Flexi,

    Thank you for your post.

    1. Correct, changing the CalculateOnBarClose does not affect the backtest. This property will always be true in a back test. If you want a more intrabar fill you will need to use a Intrabar Granularity to accomplish this. Please see the link below for more information -
    http://www.ninjatrader.com/support/f...ead.php?t=6652

    2. Your strategy is following the conditions that are being met in the code. If you want the strategy to wait after an exit, you can use BarsSinceExit() in your conditions to have it wait a certain amount of bars -
    http://www.ninjatrader.com/support/h...ssinceexit.htm


    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      I did BarsSinceExit() but it does not solve the issue because now NT is opening position
      immediatley after 5 bars for example. If I put too much bars, 3000 for example then NT ignores
      the next entry condition. It waits after 300 bars and only then it enetrs position. Is there some other way so solve the issue ?

      Comment


        #4
        Flexi,

        How are you submitting your orders?

        Can you share your script that I can further investigate this?
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          It is simple GAPS strategy. When there is a gap I want to enter a position. If it is stoped or
          if profit is taken I want to open another position only when another gap is created.
          That is imposible with BarsSinceExit() because it will ignore the next gap. My point is
          how can NT open only one position and then open another only if new gap is created.
          My code is bellow






          #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.Gui.Chart;
          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")]
          public class GAPANDRUN : Strategy
          {
          #region Variables
          // Wizard generated variables
          private int myInput0 = 1; // Default setting for MyInput0
          // 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()
          {
          SetProfitTarget("", CalculationMode.Ticks, 40);
          SetStopLoss("", CalculationMode.Ticks, 10, false);

          CalculateOnBarClose = false;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Condition set 1
          if (GAPS(Open, 1).Plot0[0] == 1
          &&(BarsSinceExit() > 30000 || BarsSinceExit() == -1))
          {
          EnterLong(1, "");
          }

          }

          #region Properties
          [Description("")]
          [GridCategory("Parameters")]
          public int MyInput0
          {
          get { return myInput0; }
          set { myInput0 = Math.Max(1, value); }
          }
          #endregion
          }
          }

          Comment


            #6
            And regarding the indicator in the code it prints 1 if there is a gap and 0 if there is no gap

            Comment


              #7
              Flexi,

              Is this GAPS something you have created or acquired from someone else?

              You said that if you take out the BarsSinceExit() that as soon as the position exits, it re-enters.
              This means the condition -
              Code:
              if (GAPS(Open, 1).Plot0[0] == 1)
              is true and why its placing the entry.

              Try loading the GAPS on the chart of the backtest and you'll see where the condition is becoming true.
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Yes that is exactly the problem. The condition is becoming true from the open to the close. So it is the entire session.

                Is there a way to apply the condition only on the first bar at the open?

                Comment


                  #9
                  This is the code of the GAPS indicator. Please tell me is there a way to apply this condition only at the first bar of the session.

                  {
                  if (CurrentDayOHL().CurrentOpen[0] >= PriorDayOHLC().PriorHigh[0] || CurrentDayOHL().CurrentOpen[0]
                  <= PriorDayOHLC().PriorLow[0])
                  Value.Set(1);

                  else Value.Set(0);
                  }

                  Comment


                    #10
                    Hello Flexi,

                    Yes, you can use Bars.FirstBarOfSession to get the when the first bar of the session has occurred.
                    http://www.ninjatrader.com/support/h...rofsession.htm
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      That work great

                      Thanks

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by cmtjoancolmenero, Yesterday, 03:58 PM
                      9 responses
                      36 views
                      0 likes
                      Last Post cmtjoancolmenero  
                      Started by DayTradingDEMON, Today, 09:28 AM
                      4 responses
                      24 views
                      0 likes
                      Last Post DayTradingDEMON  
                      Started by geddyisodin, Yesterday, 05:20 AM
                      9 responses
                      50 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by George21, Today, 10:07 AM
                      1 response
                      15 views
                      0 likes
                      Last Post NinjaTrader_ChristopherJ  
                      Started by Stanfillirenfro, Today, 07:23 AM
                      9 responses
                      24 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Working...
                      X