Gekko Trading Bot - Why Stop Losses Doesn't Work

in gekko •  7 months ago

Gekko Trading BotWhyLossesDoesn't Work.jpg

It seems like the first thing people do once they come across an awesome strategy that doesn't have stop loss is to implement one. I have to say I have spent countless hours myself at this process. But does it really work? The short version of the answer is no.

The long version is: it will sell at the stop loss that you want, but it will break the strategy by making it significantly less profitable.

Conceptually, it is pretty easy to understand. When you implement a stop loss to a strategy, it will sell at the stop loss, but then there are no rules to prevent it from buying back in. In fact, most of time, that's what ends up happening. For example, the bot bought at $100, and you set a 3% stop loss, and as soon as it sees $97, it will sell. But then the conditions that had the bot buy at $100 is still valid, so it goes back and buy again at $97. It will repeat this process until the buy conditions are no longer met. This can take place over hours or days, resulting in 6 to 7 bad stop losses.

On the other hand, if the bot was following the original strategy, it would just hodl because there were no arbitrary stop loss price that it had to sell at. So when the price finally rose back to $112 after diving to $85, it took the gains to the bank (having found conditions that met the sell state) and didn't take any losses at all.


I'm diving into this because of this post on the Gekko forum. I contributed to it but I figure it is best I create a SteemIt post about it.

From the post, the OP, bojim, tested one of the stop loss strategies that I added to the BBRSI strategy and noticed it was performing 90% worser than the original. I pretty much suggested what I said above would happen, but didn't think it would be this obvious. But before I begin, let me give you some details on the backtest setup (in case you want to replicate it):

Exchange: GDAX
Trade pair: LTC/USD
Range: January 1, 2018 - April 15, 2018
Candle Size: 10 minutes

So this is the performance.
Original: 143.93%
With Stop Loss: 50.41%

If you look at the original strategy, it takes a pretty bad hit with a loss of over 5% on February 2nd!
2018-05-07 10_48_28-Gekko.png

With the modified strategy, you can see it stopped loss multiple times near 3%, but most of the time it goes over that. The problem is the 10 minute candles. While you execute the stop loss trade at 3% loss, the backtest tool will take the next closing candle as the recorded price of the stop loss sale, resulting in loss anywhere from 3% to 5%.

But what's worse if you look at the trades more closely, while the original strategy held the 5% loss trade for 7 hours, the stop loss strategy only held it for an hour, and then bought back in 5 more times in that duration! So instead of taking a 5% loss and be done with it (the original didn't enter back into the market until the next day), the modified strategy with stop loss ended up with a whopping 25% loss for the same duration.
InkedBBRSI - LTC fail_LI.png

So is there a way to prevent this from happening? Sure! There are many ways. You can set fixed variables like a set duration where the bot does not enter the market after a stop loss trade executes. But because the bot is blind to market conditions, I seen backtests where the bot still enters into a bad trade after the set duration is up. The other situation I seen is the bot misses out in prime buying opportunities because it is just counting down a timer.


Stop losses are arbitrary set points that bots don't understand with the logic that they are provided. They just see it as a separate sell condition that will let it change its state from hodl to looking to buy. If all conditions for a buy is still valid, it will buy right back into the market and make as many losing trades as possible until the conditions to buy are no longer valid.

P.S. But this doesn't mean there's no way to improve the performance of the original strategy. I will explain more in my next post.


Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!