Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtesting exits at 12am

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

    Backtesting exits at 12am

    Am backtesting a multi-time frame strategy. The entries are working according to the code. It closes the position at 5:15pm which is great. However, the exits on close at 12am are strange. I have nothing in the code to tell it to exit at 12am. Sometimes it shows an exit on close at 12am and sometimes it holds the position thru 12am. Any thoughts? I am perplexed.

    Ken
    Last edited by kennyb59; 03-12-2014, 12:12 PM. Reason: typos and wrong title

    #2
    Hello Kennyb59,

    Thank you for your post.

    What instrument are you using?

    What time interval are you running for the backtest?

    What session template are you using?
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Cal,

      In response to your questions, using the Emini 03-14. Time frames are 5 min and daily. . Testing from 1.1.14 until today. Session template is the use the instument settings( which I assume is the 03-14 contract) and exit on close is set to true.

      Ken

      Comment


        #4
        Ken,

        Can you attach your script so that I can review it and test this on my end?

        Additionally can you provide a screenshot of the backtest and the settings you used for your strategy?

        To attach items, Reply -> Go Advanced -> Select the paperclip in the top tool bar
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Cal,

          Here is a copy of my code. I have also attached the settings and the trades that executed in backtesting during 2014. I really appreciate your assistance.

          #region Variables
          // Wizard generated variables
          private int profitTarget = 55; // Default setting for ProfitTarget
          private int stopLoss = 21; // Default setting for StopLoss
          private bool barDown = true; // Default setting for BarDown
          private int rSIlimit = 30; // Default setting for RSIlimit
          private int aDXlimit = 50; // Default setting for ADXlimit
          private int BarsRequired = 30;
          // 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.Day, 1);

          Add (AaMACD(7, 25, 30));
          Add (ADX(8));
          Add (RSI(8,3));

          SetProfitTarget("AaMacdShort", CalculationMode.Ticks, ProfitTarget);
          SetStopLoss("AaMacdShort", CalculationMode.Ticks, StopLoss, false);

          CalculateOnBarClose = true;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          if (BarsInProgress == 0)
          {
          if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
          return;

          if (AaMACD(BarsArray[2],7, 25, 30).FastMacdRising.ContainsValue(0))
          //|| AaMACD(BarsArray[2],7, 25, 30).FastMacdFalling.ContainsValue(0))
          return;

          if (AaMACD(BarsArray[2],7, 25, 30).FastMacdFalling.ContainsValue(0)
          //(AaMACD(BarsArray[2],7, 25, 30).FastMacdFalling[0] < AaMACD(BarsArray[2],7, 25, 30).FastMacdFalling[1]
          && (RSI(BarsArray[2],8, 3).Avg[0] > 30)
          && (RSI(BarsArray[1],8, 3).Avg[0] > 30)
          && (CrossBelow(AaMACD(BarsArray[1], 7, 25, 30).FastMacdFalling, 0, 1)))
          {
          EnterShort(DefaultQuantity, "AaMacdShort");
          }

          The exits are just the profit targets. I can also send to you the AaMacd code which is an indicator I found on Big Mike's Trading Forum.

          Ken
          Attached Files

          Comment


            #6
            Kenny,

            I would like to test this out on my end.

            If you could please export the script and attach the .ZIP I will be able to import it and run some backtests.

            1. From the Control Center window select the menu File > Utilities > Export NinjaScript to open the "Export NinjaScript" dialog window

            2. Select the option "Export selected source files"

            3. Enter a user defined file name

            4. Select all of the files that you want to export and either double click on them or press the ">" button

            5. A list of all files that will be exported

            6. Press the "Export" button to export the selected files

            7. A NinjaScript Archive File (.zip) file will be created in My Documents\<NinjaTrader Folder>\bin\Custom\ExportNinjaScript
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Hi Cal,

              My father, kennyb59, is having difficulty exporting from his ninjatrader. So I will import it from my end. It includes the indicator needed.

              The problem my father is having hasn't been happening on my computer. It wasn't until I compared our back test results that I noticed that his system was closing on some dates as a close on exit at 12 am. Which our close on exit is supposed to be at 5:14pm.

              Thanks,
              Sam
              Attached Files

              Comment


                #8
                Ken,

                Can you try testing with the SampleMACrossOver. Do you get the same results with this strategy?

                Can you check the chart data, does it stop short at the 12:00 AM bar?
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Cal,

                  Good question. I ran the sample MAcrossover 30min since the beginning of the year. Not a single exit at 12am. However, there are abrupt changes in data at 12am on the days it exits.

                  Ken

                  Comment


                    #10
                    Ken,

                    Let's setup a remote session.

                    Can you send me a request to support[at]ninjatrader[dot]com and put ATTN Cal in the subject and a reference to this thread in the body
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      Cal,

                      Thx Cal. For sure. Will do this afternoon after 3pm EST.

                      Ken

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Rapine Heihei, Today, 08:19 PM
                      1 response
                      8 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by Rapine Heihei, Today, 08:25 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post Rapine Heihei  
                      Started by f.saeidi, Today, 08:01 PM
                      1 response
                      9 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by Rapine Heihei, Today, 07:51 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post Rapine Heihei  
                      Started by frslvr, 04-11-2024, 07:26 AM
                      5 responses
                      98 views
                      1 like
                      Last Post caryc123  
                      Working...
                      X