Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtesting and multitimeframe intrabar fills

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

    Backtesting and multitimeframe intrabar fills

    Hi,

    During backtesting different strategies I ran into fills I simply could not understand when using 1440min bars as primary and 5-60min as secondary.
    So I created this testscript to understand the problem but it is still showing up and I cannot understand it. Maybe someone can help.

    The strategy is attached and when I run it on 6S 06-11 dates 1.february forward I get a fill like in the attached pic. 77ticks above the level.

    Thanks for any help.

    Code:
    #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 intrabarteststrat : Strategy
        {
            #region Variables
            // Wizard generated variables
            private double longlevel = 1.070; // Default setting for Longlevel
            // 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()
            {
                CalculateOnBarClose = true;
    			Add(PeriodType.Minute,5);
    			ExitOnClose=false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    //			if (BarsInProgress == 1) {
                if (Close[0] > Longlevel)
                {
                    EnterLong(1,DefaultQuantity, "long");
                }
    //			}
    			
    			
    			
            }
    
            #region Properties
            [Description("")]
            [GridCategory("Parameters")]
            public double Longlevel
            {
                get { return longlevel; }
                set { longlevel = Math.Max(1, value); }
            }
            #endregion
        }
    }
    Attached Files
    Last edited by naxo79; 04-06-2011, 02:42 PM.

    #2
    Hello naxo79,

    It looks OK. The bar prior to the fill is the first bar that closes above your level and an order is submitted on the next bar following the condition. It will be submitted to the open of the first 5 minute bar that takes place after the trigger bar.

    Excerpted below is the example from this reference sample on multiple bar series in a backtest.

    When working with multiple bar series objects it is important to understand the sequential order in which the OnBarUpdate() method is triggered. The bars will always run with the primary first followed by the secondary and so on.

    Important: Primary bars will always execute before the secondary bar series.
    If a bar is timestamped as 12:00PM on the 5min bar series, the call order between the equally timestamped 12:00PM bar on the 1min bar series is like this:
    12:00PM 5min
    12:00PM 1min
    12:01PM 1min
    12:02PM 1min
    12:03PM 1min
    12:04PM 1min
    12:05PM 5min
    12:05PM 1min
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      Thank you.

      What I am trying to do is to enter once the condition > 1.070 is fulfilled on the 5min.
      Ie. Get an entry as close to 1.070 as possible.
      But that seems not really possible?


      update:
      Having this
      if (BarsInProgress == 1) {
      uncommented doesnt change the fill as I thought it should since the condition should be evaluated on the 5min bars
      Last edited by naxo79; 04-06-2011, 03:21 PM.

      Comment


        #4
        Getting entries at a specific price is possible, but the backtesting model will always be:
        Condition evaluates true > Order submitted on next bar following the condition.

        See here for discrepancies expected real time compared to a backtest.


        If you want to enter at a specific price, then submit EnterLongStop() to a specific value. You will just have to control the submission of the order so that you're not submitting a buy stop order below the last traded price.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          Getting entries at a specific price is possible, but the backtesting model will always be:
          Condition evaluates true > Order submitted on next bar following the condition.

          See here for discrepancies expected real time compared to a backtest.


          If you want to enter at a specific price, then submit EnterLongStop() to a specific value. You will just have to control the submission of the order so that you're not submitting a buy stop order below the last traded price.
          Tnx, doing tests using EnterLongStop order now.

          But, so its not possible to evaluate the condition on the finer granularity and having the order triggered by the condition being fulfilled on the finer granularity timeframe?

          Comment


            #6
            Hi,

            Ok possibly, got it working maybe by adding the BarsInProgress ==0 and 1 statements. Gotta continue testing and experimenting.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Felix Reichert, 04-26-2024, 02:12 PM
            5 responses
            39 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
            15 responses
            45 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by ETFVoyageur, Yesterday, 06:05 PM
            6 responses
            37 views
            0 likes
            Last Post ETFVoyageur  
            Started by rbeckmann05, Today, 02:35 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by Torontobluejays, Yesterday, 08:43 AM
            6 responses
            34 views
            0 likes
            Last Post rc5781
            by rc5781
             
            Working...
            X