Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Slippage not calculated correctly

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

    Slippage not calculated correctly

    Hi,

    I'm backtesting a system using markets orders only.
    I compared the results trade per trade of a strategy running with no slippage and a strategy running with 1 tick of slippage.
    Sometimes for the same trade, the P&L difference is only 1 tick instead of being 2 (entry and exit).
    Looking at the charts, I noticed that this is coming from NT not taking into account 1 tick of slippage for a buy if the high of the first bar after the signal = the opening price of that same bar (low of the next bar = opening price for a sell).

    Please see attached charts. The 2 charts on the left assume 1 tick slippage and the 2 charts on the right assume no slippage.
    The 2 charts on the top are the same trade with different assumed slippage, the 2 charts on the bottom are the same trade with different assumed slippage.
    In the top left red square NT assumes that because 3151 was the high of the bar, it couldn't have any slippage. However 3151 could have been the bid at the opening and my market order would have printed 3152 in real conditions.
    Same for the closing trade in the yellow square on the bottom left.
    I don't know if this is a known issue, but it needs to be corrected.

    Hope it makes sense
    Attached Files

    #2
    Hello,

    I see what you're saying and thanks for writing this up.

    I'm checking with development for further clarification on this behavior.
    MatthewNinjaTrader Product Management

    Comment


      #3
      This would be expected when the High and the Open are the same price as there is not a price to be filled at higher. The bid/ask prices will not be used in this case.

      For clarification, you can review how the fill price is determined by going to Documents\NinjaTrader 7\bin\Custom\Type\@DefaultFillType.cs

      Code:
      /* *** 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
      
      if (order.OrderType == OrderType.Market)
      			{
      				if (order.OrderAction == Cbi.OrderAction.Buy || order.OrderAction == Cbi.OrderAction.BuyToCover)			// set fill price
      					FillPrice = Math.Min(NextHigh, NextOpen + SlippagePoints);
      				else
      					FillPrice = Math.Max(NextLow, NextOpen - SlippagePoints);
      			}
      For a buy order, it will take the min value of the next bars high and open and add your slippage value. Since there is no price higher than high/open of that bar, there will not be any slippage.

      If you'd like to change this, it is possible to program your own custom FillType to backtest on.
      MatthewNinjaTrader Product Management

      Comment


        #4
        " * Slippage can only be applied to if the bar the order is filled on could have accomodated slippage "

        So I assume I can't write something like this?

        FillPrice = NextOpen + SlippagePoints;

        Comment


          #5
          Hello,

          You can rewrite it to meet whatever you feel would work to meet your expectations.
          MatthewNinjaTrader Product Management

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by arvidvanstaey, Today, 02:19 PM
          4 responses
          11 views
          0 likes
          Last Post arvidvanstaey  
          Started by samish18, 04-17-2024, 08:57 AM
          16 responses
          60 views
          0 likes
          Last Post samish18  
          Started by jordanq2, Today, 03:10 PM
          2 responses
          9 views
          0 likes
          Last Post jordanq2  
          Started by traderqz, Today, 12:06 AM
          10 responses
          18 views
          0 likes
          Last Post traderqz  
          Started by algospoke, 04-17-2024, 06:40 PM
          5 responses
          47 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X