Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Tick by tick Backtest

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

    Tick by tick Backtest

    If we subscribe kinetick(forex), it will do the backtest tick by tick, if yes, then it will play the data as live trading?. I want to confirm if my strategy will trade intrabar as I wrote in my code,..... My base and main question is, does kinetick will provide history look like live trade???

    #2
    Hello forexx,

    Backtests are not done tick by tick unless you backtest using a 1 tick interval. A backtest will only know OHLC values of the interval you select - it will not be intrabar. More information regarding backtests can be found at the link below.


    I am not sure if I understand your last inquiry. Kinetick does support historical and real-time data. NinjaTrader acts like a radio receiver and displays the data it receives.
    JasonNinjaTrader Customer Service

    Comment


      #3
      Will back testing on Tick.Last series call Bid and Ask tick data as well?

      I have a question regarding tick by tick back testing.
      I want to know if I backtesting will be done against bid/ask price if I select the Tick.Last price as dataseries in Strategy Analyzer.

      I'm asking this question because I found following post.

      =======================


      Posted by RedEyeFly on 09-15-10 04:50 AM:

      Thank you guys for all your input. I just found that NT 7 will take both the bid and ask data for tick backtesting so I'm going to give NT a try.

      Thanks!
      =======================


      I have Kinecick Forex subscription and believe I can get Historical Bid/Ask tick data.
      If I backtest my forex strategy using Tick "Last", will my strategy enter and exit using the Bid/Ask price and behave as follows?

      EnterLongLimit will trigger when Tick.Ask price is lower than the Limit price
      EnterShortLimit will trigger when Tick.Bid price is higher than the Limit price

      I can only select Tick "Last" or "Bid" or "Ask" for dataseries on Strategy Analyzer so I will assume that selecting "Last" will call both Bid and Ask.


      I'm asking this question because, as you know in most forex brokers, you can only trade against the price quoted by the market makers. So backtesting for limit orders on Ninja platform using the Last price is not realistic (you cannot set slippage on limit orders). Ninja strategy analyzer using the Last price is good for instruments traded in the exchange but when you have no option but to trade against market makers, it would need to be able to use both Bid and Ask price to get reailstic simulation results.


      Would appreciate your response.

      Comment


        #4
        Originally posted by hana_maui View Post
        I have a question regarding tick by tick back testing.
        I want to know if I backtesting will be done against bid/ask price if I select the Tick.Last price as dataseries in Strategy Analyzer.

        I'm asking this question because I found following post.

        =======================


        Posted by RedEyeFly on 09-15-10 04:50 AM:

        Thank you guys for all your input. I just found that NT 7 will take both the bid and ask data for tick backtesting so I'm going to give NT a try.

        Thanks!
        =======================


        I have Kinecick Forex subscription and believe I can get Historical Bid/Ask tick data.
        If I backtest my forex strategy using Tick "Last", will my strategy enter and exit using the Bid/Ask price and behave as follows?

        EnterLongLimit will trigger when Tick.Ask price is lower than the Limit price
        EnterShortLimit will trigger when Tick.Bid price is higher than the Limit price

        I can only select Tick "Last" or "Bid" or "Ask" for dataseries on Strategy Analyzer so I will assume that selecting "Last" will call both Bid and Ask.


        I'm asking this question because, as you know in most forex brokers, you can only trade against the price quoted by the market makers. So backtesting for limit orders on Ninja platform using the Last price is not realistic (you cannot set slippage on limit orders). Ninja strategy analyzer using the Last price is good for instruments traded in the exchange but when you have no option but to trade against market makers, it would need to be able to use both Bid and Ask price to get reailstic simulation results.


        Would appreciate your response.
        I should think that would be automatically the case if you just use Mar****rders instead.

        Comment


          #5
          Hello hana_maui,

          If you backtest a strategy based on Last price data, it will use Last price data to run your backtest. It does not use Bid or Ask data.

          Please note that the algorithm you have selected determines how limit and stop orders are filled. Please see the link below for more information under 'Understanding historical processing options'.
          JasonNinjaTrader Customer Service

          Comment


            #6
            Dear Mr. Jason,

            Thank for the reply.
            I have read in another thread the way of using Variable0 - Variable9 and changing the FillType.
            I have tried in the following way, but do not seem to be getting the correct fill.
            What I'm trying to do is just have the buy order to be triggered on the Ask price, and sell order to be triggered on the Bid price.

            Could you kindly advise me on what is wrong?


            For your information, the backtest is done on Last Tick.
            And I have added following codes to my strategy.

            protected override void Initialize()
            {
            Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask);
            Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid);
            Add(Instrument.FullName, PeriodType.Minute, 1, MarketDataType.Last);
            }

            protected override void OnBarUpdate()
            {
            if(BarsInProgress == 1)
            {
            Variable0 = Close[0]; //Ask (You can Buy)
            Variable2 = High[0]; //Ask (You can Buy)
            Variable4 = Low[0]; //Ask (You can Buy)
            }
            else if(BarsInProgress == 2)
            {
            Variable1 = Close[0]; //Bid (You can sell)
            Variable3 = High[0]; //Bid (You can sell)
            Variable5 = Low[0]; //Bid (You can sell)
            }

            else if(BarsInProgress == 0)
            {
            This is where my strategy code comes.
            }

            And I have made the Following FillType.
            //
            // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
            //
            #region Using declarations
            using System;
            using System.ComponentModel;
            using System.Drawing;
            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>
            /// </summary>
            [Gui.Design.DisplayName("Backtest")]
            public class BacktestFillType : FillType
            {
            private const double epsilon = 0.00000001;
            /// <summary>
            /// Processes a historical order and checks for potential fills.
            /// </summary>
            /// <param name="order">Historical order to process</param>
            public override void Fill(Order order)
            {
            /* *** Slippage ***
            * Slippage values are optionally set in the UI and only applied to market and stop market orders
            * Slippage can only be applied to if the bar the order is filled on could have accomodated slippage
            *
            * *** Limit Orders ***
            * Limit orders are filled if the limit price is traded through
            * For example, if the limit price of a sell limit order equals the high of the bar it will not fill
            * The limit price must be less than the high of the bar to fill */
            if (order.OrderType == OrderType.Market)
            {
            if (order.OrderAction == Cbi.OrderAction.Buy || order.OrderAction == Cbi.OrderAction.BuyToCover) // set fill price
            FillPrice = Strategy.Variable0;
            else FillPrice = Strategy.Variable1;
            }
            else if (order.OrderType == OrderType.Limit)
            {
            // Orders are filled when traded through the limit price not at the limit price
            double nextLow = NextLow;
            double nextHigh = NextHigh;
            if ( (order.OrderAction == Cbi.OrderAction.Buy && order.LimitPrice > Strategy.Variable4 + epsilon)
            || (order.OrderAction == Cbi.OrderAction.BuyToCover && order.LimitPrice > Strategy.Variable4 + epsilon)
            || (order.OrderAction == Cbi.OrderAction.Sell && order.LimitPrice < Strategy.Variable3 - epsilon)
            || (order.OrderAction == Cbi.OrderAction.SellShort && order.LimitPrice < Strategy.Variable3 - epsilon))
            FillPrice = order.LimitPrice; // set fill price
            }
            else if (order.OrderType == OrderType.Stop)
            {
            // Stop orders are triggered when traded at the stop price
            double nextLow = NextLow;
            double nextHigh = NextHigh;
            double nextOpen = NextOpen;
            if ( (order.OrderAction == Cbi.OrderAction.Buy && order.StopPrice <= Strategy.Variable2 + epsilon)
            || (order.OrderAction == Cbi.OrderAction.BuyToCover && order.StopPrice <= Strategy.Variable2 + epsilon)
            || (order.OrderAction == Cbi.OrderAction.Sell && order.StopPrice >= Strategy.Variable5 - epsilon)
            || (order.OrderAction == Cbi.OrderAction.SellShort && order.StopPrice >= Strategy.Variable5 - epsilon))
            {
            if (order.OrderAction == Cbi.OrderAction.Buy || order.OrderAction == Cbi.OrderAction.BuyToCover)
            FillPrice = order.StopPrice < nextOpen - epsilon ? Math.Min(nextHigh, nextOpen + SlippagePoints) : Math.Min(nextHigh, order.StopPrice + SlippagePoints);
            else
            FillPrice = order.StopPrice > nextOpen + epsilon ? Math.Max(nextLow, nextOpen - SlippagePoints) : Math.Max(nextLow, order.StopPrice - SlippagePoints);
            }
            }
            else if (order.OrderType == OrderType.StopLimit)
            {
            // Stop limit orders are triggered when traded at the stop price and traded through the limit price
            double nextLow = NextLow;
            double nextHigh = NextHigh;
            if (!order.StopTriggered
            && ((order.OrderAction == Cbi.OrderAction.Buy && order.StopPrice <= Strategy.Variable2 + epsilon)
            || (order.OrderAction == Cbi.OrderAction.BuyToCover && order.StopPrice <= Strategy.Variable2 + epsilon)
            || (order.OrderAction == Cbi.OrderAction.Sell && order.StopPrice >= Strategy.Variable5 - epsilon)
            || (order.OrderAction == Cbi.OrderAction.SellShort && order.StopPrice >= Strategy.Variable5 - epsilon)))
            order.StopTriggered = true; // stop limit order was triggered
            if (order.StopTriggered
            && ((order.OrderAction == Cbi.OrderAction.Buy && order.LimitPrice > Strategy.Variable4 + epsilon)
            || (order.OrderAction == Cbi.OrderAction.BuyToCover && order.LimitPrice > Strategy.Variable4 + epsilon)
            || (order.OrderAction == Cbi.OrderAction.Sell && order.LimitPrice < Strategy.Variable3 - epsilon)
            || (order.OrderAction == Cbi.OrderAction.SellShort && order.LimitPrice < Strategy.Variable3 - epsilon)))
            FillPrice = order.LimitPrice; // set fill price
            }
            }
            }
            }

            Comment


              #7
              Hi hana_maui,

              You're free to create your own fill type. Unfortunately we could not debug it for you. If you are looking for professional code development services, please see our NinjaScript constulants available here:
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Dear Mr. RyanM,

                Thank for the feedback.
                I will try and figure out the solution then.
                Thanks.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by prdecast, Today, 06:07 AM
                0 responses
                3 views
                0 likes
                Last Post prdecast  
                Started by i019945nj, 12-14-2023, 06:41 AM
                3 responses
                60 views
                0 likes
                Last Post i019945nj  
                Started by TraderBCL, Today, 04:38 AM
                2 responses
                18 views
                0 likes
                Last Post TraderBCL  
                Started by martin70, 03-24-2023, 04:58 AM
                14 responses
                106 views
                0 likes
                Last Post martin70  
                Started by Radano, 06-10-2021, 01:40 AM
                19 responses
                610 views
                0 likes
                Last Post Radano
                by Radano
                 
                Working...
                X