Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Understanding slippage & fill algorithms

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

    Understanding slippage & fill algorithms

    Hi-

    I have a question regarding the calculation NT makes with regards to slippage and the fill algorithm used.

    If I have the fill algorithm set to the "more strict" version (limit orders must trade through), AND I set slippage to 1 tick, what price would be used for a limit sell order?

    For example, if I want to sell 1 ES @ 1,000, what does NT calculate as the actual fill price in the above scenario? Must ES trade to 1000.25, and I sold at 999.75?

    #2
    Hello cgeorgan,

    You can view the code used for the fill price by browsing to:

    My Documents\NinjaTrader\bin\custom\type

    Some notes from the DefaultFillType.cs file:

    /* *** 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.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);
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thank you, got it.

      Comment


        #4
        One more...

        When it comes to market orders in "live testing", is this the same algorithm used? For example, I'm using tick data and the bids/offers are available. Does the fill algo take into account the posted offer when buying @ the market + slippage points, or does it use the algorithm below?

        Comment


          #5
          Actually, a better question-

          So I'm in the DefaultFillType file, and I see what's going on.

          I'd like to modify it for myself as suggested, so that I can use GetCurrentBid() (and offer) in certain cases.

          If I make adjustments in the Custom/Type directory and save them, will everything in that directory (including my changes) re-compile when I run compile on any other custom function? Not sure how it works -

          Comment


            #6
            Cgeorgan,

            When running a strategy live, these fill algorithms are not used. Market orders are filled at either the bid / ask depending on direction.

            You can create your own fill type, but you should create a new file.

            Below are some changes to the code you would need to make this custom fill type.
            Gui.Design.DisplayName("Custom")]
            public class CustomFillType : FillType
            {

            Yes, any changes made here to files will be reflected in your NinjaTrader when you recompile.

            Since this is used historically, you might not get the results you expect if you plug in GetCurrentBid() as this is a real time value.

            For submitting orders at either the bid or ask in real time, you should add these series to your strategy and then submit orders on BIP 1 or 2.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_RyanM View Post
              Cgeorgan,

              When running a strategy live, these fill algorithms are not used. Market orders are filled at either the bid / ask depending on direction.

              You can create your own fill type, but you should create a new file.

              Below are some changes to the code you would need to make this custom fill type.
              Gui.Design.DisplayName("Custom")]
              public class CustomFillType : FillType
              {

              Yes, any changes made here to files will be reflected in your NinjaTrader when you recompile.

              Since this is used historically, you might not get the results you expect if you plug in GetCurrentBid() as this is a real time value.

              For submitting orders at either the bid or ask in real time, you should add these series to your strategy and then submit orders on BIP 1 or 2.
              Thanks for that.

              I'm assuming that the Historical() check works within the fill algorithms, so that if this is historical I can use the default vs. a new algorithm if it's live -

              Comment


                #8
                Not necessarily. The fill algorithms are only used on an historical basis. When your strategy runs live then fills are determined by the market if you're trading on a live account, or by our simulator engine if you're trading on Sim101.

                See here for discrepencies expected when running a backtest versus live.

                The code for the simulator engine is not available. Below is a brief description from our help guide:

                NinjaTrader provides a state of the art internal simulation engine that you can use to test trading ideas and hone your skills. The simulation engine is not a simple algorithm that fills your order once the market trades at your order price. The engine uses a scientific approach to determine fill probability by including a number of variables including ask/bid volume, trade volume, time (to simulate order queue position) and random time delay for switching between order states.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_RyanM View Post
                  Not necessarily. The fill algorithms are only used on an historical basis. When your strategy runs live then fills are determined by the market if you're trading on a live account, or by our simulator engine if you're trading on Sim101.

                  See here for discrepencies expected when running a backtest versus live.

                  The code for the simulator engine is not available. Below is a brief description from our help guide:

                  NinjaTrader provides a state of the art internal simulation engine that you can use to test trading ideas and hone your skills. The simulation engine is not a simple algorithm that fills your order once the market trades at your order price. The engine uses a scientific approach to determine fill probability by including a number of variables including ask/bid volume, trade volume, time (to simulate order queue position) and random time delay for switching between order states.
                  OK, moving forward here. I didn't know the code was unavailable. Do you know (or could you ask your programmers) if the simulator engine will buy on the offer and sell on the bid for market orders? And if I tack on 1 tick of slippage, will market orders then fill me on the ask +1 or bid -1?

                  Comment


                    #10
                    Yes, market orders are filled on the offer for buy orders and on the bid for sell orders.

                    Slippage does not apply to real time market orders.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      A clarification please. I am running several strategies in simulation on live data from IB. The strategies usually are trying to buy and sell securities at the same instant using market orders. I would like to ensure that when a buy market order is triggered that it hits the ask and a sell market order hits the bid at the same time.

                      Also I would like to ensure that this remains the case at all times and does not change based on what value is set in the New Strategy window. If I change it from Last to bid or ask, I expect that market orders would still behave as described above.

                      Thanks!
                      Attached Files

                      Comment


                        #12
                        Hello,

                        You have no say on where a market order is filled. This is general trading / how market orders work. The fill at the current price the market decides to fill you at.

                        If you want to specify a certain price or better to be filled at you would need to use Limit orders.

                        Let me know if I can be of further assistance.

                        Comment


                          #13
                          Hi Brett,

                          Let me try to be more specific. Does the "Price Based on" setting in the strategy window affect how NT reports the price fill during an execution? My assumption is that a fill uses the live bid/ask prices for a market order and reports those as the fill price, and that whether the setting is set to Last, Bid or ask does not affect the fill price.

                          I also assume that these settings affect the OHLC prices of each historical bar. So if my strategy uses historical bar information than these values would be affected the "price based on" setting?

                          Thanks,
                          Mike

                          Comment


                            #14
                            Hi Mike,

                            That setting will change the series that the strategy is run against but this will not change the way the simulator will fill you in real time or historically.

                            Historically there will be different bars, so there will be different fills because of this.

                            In real time, there is no change since the live bid/ ask data is the same regardless of the "price based on" selection.
                            Ryan M.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by MarianApalaghiei, Today, 10:49 PM
                            2 responses
                            8 views
                            0 likes
                            Last Post MarianApalaghiei  
                            Started by love2code2trade, Yesterday, 01:45 PM
                            4 responses
                            28 views
                            0 likes
                            Last Post love2code2trade  
                            Started by funk10101, Today, 09:43 PM
                            0 responses
                            8 views
                            0 likes
                            Last Post funk10101  
                            Started by pkefal, 04-11-2024, 07:39 AM
                            11 responses
                            37 views
                            0 likes
                            Last Post jeronymite  
                            Started by bill2023, Yesterday, 08:51 AM
                            8 responses
                            46 views
                            0 likes
                            Last Post bill2023  
                            Working...
                            X