Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limiting Slippage

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

    Limiting Slippage

    I am current trading oil, gold, silver and copper. My live strategy reflects my backtests accurately, except for the losses due to slippage. Typically one tick on half of my trades. This will amount to approx 6% loss in gains per year.

    I am currently exiting with stop orders, I'd like to change this to a stop limit with a safety that if a tick price comes through past my limit price, then it will submit a market order.

    I need to know where the absolute fastest place to put the code for this price check is, without running into order fill conflicts. I don't want the order to be getting filled, and have my strategy submit a market order because a tick came through before the strategy could know the stop limit was filled.

    Thanks,

    #2
    Hello waynewright33,

    Thank you for your post.

    I would check the OrderState of the Stop Limit order in the OnBarUpdate() method before cancelling the Stop Limit and submitting the market order. However, there is always going to be the chance that a race condition occurs where we get two orders conflicting with each other due to the nature of how you wish to submit this market order.

    I would recommend familiarizing your self wit the internal order handling rules at the following link: http://www.ninjatrader.com/support/h...d_approach.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      Say in onbarupdate(tick) I check if the price has broken my stop, then I check the orderstate and it returns not filled, if I send a cancel order request on the next line, then a market order on the following line, would that be my best bet? Or do I need to send the cancel request, check the order state on the next tick, then send the market order?
      Last edited by waynewright33; 08-25-2014, 12:55 PM.

      Comment


        #4
        I suppose I should cancel the order, and then place the market order in the on order update ?

        Comment


          #5
          Hello waynewright33,

          Thank you for your response.

          Checking the cancel went through in OnOrderUpdate() would be the best idea here.

          Comment


            #6
            I'm adjusting my stops using onmarketdata (kinetic), broker is IB.

            If I check Position.MarketPosition == MarketPosition.Long && e.Price < stopOrderLong.StopPrice

            then issue a CancelOrder() if true, will the position check be correct?

            I've read posts from your staff saying both,that it won't update until a new bar update, and that that only applies when backtesting, and that it will be right when live.
            Last edited by waynewright33; 08-26-2014, 12:09 PM.

            Comment


              #7
              Hello waynewright33,

              Thank you for your note.

              The OnMarketData() method is only a real-time data stream. As backtesting is on historical data, this will not work in backtesting. OnMarketData() is not called on historical data and will not work in backtesting.

              Comment


                #8
                I'm talking about my live strategy here?

                I've read your staff say that the it only updates after an onbarupdate, and I've also read them say that that rule only applies when backtesting.

                Comment


                  #9
                  Hello waynewright33,

                  Thank you for your response.

                  OnMarketData() is called when the last, bid, ask, or volume changes. It does not work in historical and is called whenever market data updates, not after OnBarUpdate() is called.

                  Comment


                    #10
                    Originally posted by waynewright33 View Post
                    I'm adjusting my stops using onmarketdata (kinetic), broker is IB.

                    If I check (Position.MarketPosition == MarketPosition.Long && e.Price < stopOrderLong.StopPrice)

                    then issue a CancelOrder() if true, will the POSITION check be correct?
                    I'm asking if my POSITION check will be correct or not. Obviously on market data won't work in a backtest. I've read conflicting results from NT staff about whether or not Position.____ gets updates instantly or not.

                    Thank you,

                    Comment


                      #11
                      Originally posted by waynewright33 View Post
                      I'm asking if my POSITION check will be correct or not. Obviously on market data won't work in a backtest. I've read conflicting results from NT staff about whether or not Position.____ gets updates instantly or not.

                      Thank you,
                      Position does not depend on OBU, hence why there is a Position update event handler. A glance through the log shows that Position is almost, if not always, updated immediately after an execution takes place.

                      Comment


                        #12
                        Roger that, so my only fear is that my kinetic data will feed my strategy a price below my stop limit before IB sends the order filled status to NT? Should I be concerned about this?

                        Comment


                          #13
                          Originally posted by waynewright33 View Post
                          Roger that, so my only fear is that my kinetic data will feed my strategy a price below my stop limit before IB sends the order filled status to NT? Should I be concerned about this?
                          That would depend on the dynamics of what you are doing. Why is it a concern in this case?

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          661 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          375 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          110 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          574 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          580 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X