How best to avoid slippage when automating?

Discussion in 'Automated Trading' started by schizo, Dec 12, 2019.

  1. schizo

    schizo

    This has been one single biggest dilemma/conundrum since I've started implementing automation. Not exactly HFT, but it does a lot of small scalping trades. Backtest reveals numerous 1-tick trades (eg. ES bought at 3100 and quickly sold at 3100.25 and the like). All of the trades are market orders and they go from long to short and vice versa. In reality, I would need more than just a tick to break even with market orders. Any good suggestions?
     
    Nobert likes this.
  2. 1. Use tick data to backtest so you can have more realistic fills, though I can't imagine you can emulate scalping without order book data.
    2. Use limit orders and cancel within some time frame if they are unfilled

    The rest is up to daddy market.
     
    schizo likes this.
  3. Developer

    Developer

    I am using the "Last" tick to place the order, but the "Bid" and "Ask" ticks to fill them.
    It doesn't avoid slippage nor does it make my logic any better, but it simulates fills much closer to reality.
     
    murray t turtle likes this.
  4. trend2009

    trend2009

    what do you mean bid and ask tick to fill them? do you mean you buy on the bid and sell on the ask?
     
  5. trend2009

    trend2009

    I did not have good experience when i used market to scalp spy. I was much better off to sit on the bid and wait for others to hit me.
     
  6. 2rosy

    2rosy

    is there any relationship between Last and bid/ask?
     
  7. Developer

    Developer

    Yes, just the other way around.

    I would not say relationship, but it can help considering both when backtesting your algo.

    Algos are often based on the last tick, which might give you nice results in backtesting.
    Especially when you run the tape "tick by tick" and your orders and stops are only or two ticks small, like the one's from the op.
    But the results in live testing might be much worse.
    The reason is, that your algo was triggered by the "Last" order, which is already gone at the time.
    And only the next bid's or ask' will tell you, when "Your" order might get executed.

    So what I do in backtesting to get IMHO more realistic results:
    - Use the "Last" tick (based on my algo) only to create an order in "Placed" state
    - And wait for the next "Ask" or "Bid" tick (having the same or a better price) to change the order to "Filled"
    - Or change the order to "Cancelled" if my order times out.
    Thats also how IB paper accounts are doing it, based on my experience.

    For Example
    My algo tells me to BUY at 15:30 during my backtesting.
    So I've add an (simulated) order which looks like:
    - Symbol: ES
    - Price: 3100
    - Action: Buy
    - Created: 15:30:00
    - Expires: 15:31:00
    - State: Placed
    Then i search at the tape for a tick which
    - was an Ask order (because somebody needs to buy from me)
    - has a price of 3100 or less (because I want to buy)
    - and was after the last tick (at 15:30:00) as well as before 15:31:00
    If that exists, i change my (simulated) order to "Filled" otherwise to "Cancelled"

    In that way, my simulated results are hopefully more realistic (at least they are much worse :( )

    Hope that makes it more clear.
     
    Last edited: Dec 12, 2019
    yc47ib likes this.
  8. tommcginnis

    tommcginnis

    Yes: don't even go near the market unless it is giving you a satisfactory range in which to trade.
    If you can't trade a flat market, STFOut.
    For example, for the ES -- if you're shooting for 25¢/1-tick, then set a Go/No_Go in front of you algo for 75¢/3-ticks. If you don't have an ATR(6minute) of 0.75? STFOut.

    Thus, even in a flat market (but with a 6minute ATR of 75¢), you can get hit at 3170.50/long, and have some pretty solid probability that 3170.75 is a minute-or-less away.

    This will cut the number of trading minutes by a good amount -- it wasn't even doable until a year or so ago -- but show me a tick-scalper who doesn't test the waters, and I'll show you an unhappy trader (with a lot of sand in his teeth :confused:).
     
  9. Tora

    Tora

    It seems to me that the best way to avoid slippage is a normal terminal, which will allow you to execute trades on time. Then, when you have planned it yourself. And I honestly do not know how to determine it in advance. Such nuances are found out only in the process of trading. Although sometimes there are such difficult situations on the market, when it is simply impossible to avoid. And here, only risk management and the emphasis on long-term positions, which leave a greater range of time for buying, can secure it. I see no other way out.
     
  10. your trading the wrong direction if you are getting slippage.
     
    #10     Dec 25, 2019
    murray t turtle and Handle123 like this.