Trade rate on dry-run falls outside candle

When you are dry-running your bot, some of you may have ran across this problem. For instance, your long trade’s entry rate was 10, even though the candle’s high rate at the time was only 9. Alternatively, your long trade’s exit rate was 5, despite the candle’s low rate being only 6 at the time. What’s the reason? It’s easy. It is the outcome of the orderbook and market orders.

Before I explain more, you need to read this, and take note of these points

  • Orders are simulated, and will not be posted to the exchange.
  • Market orders fill based on orderbook volume the moment the order is placed.

So let’s say you wish to use a market order to enter a long trade of coin A. The bot then retrieved the exchange’s current orderbook for coin A and obtained this orderbook.

Rate  Amount

105      10
104       5
103       3
102       1
101       2 # ask
-------------Current spread
99        3 # bid
98        3
97        1
96        6
95       20

You now wish to purchase 8 coins. Given that you are using a market order (as previously said), the bot would buy 2 coins at 101, 1 coin at 102, 3 coins at 103, and 2 coins at 104, with an average entry rate of 102.625. However, if you examine the candle at that very moment, the high was, for instance, merely 101.34. Why? because, as was already mentioned, your orders are never posted to the exchange. However, you would notice the candle shift to that rate if your trade is a live trade and the orders actually post to the exchange.

So how to avoid such “bug”? It’s simple.

  • Use limit orders. Personally, I’m using limit order for entry and market order for exit.
  • Trade only pairs with good liquidity. Make a rolling check to ensure that none of the previous x candles had 0 volume as an in-strat filter.

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *