Trading bot mistakes: live trading

When backtesting and live-trading results don't match πŸ”₯β˜•οΈπŸΆπŸ”₯

Trading bot mistakes: live trading

I made a bunch of mistakes while setting up backtesting in my bot, so I was pretty scared about what would go wrong when it came to the bot making real trades in the wild.

My broker offers simulated trading, so my bot was happily trading in that test environment for a while before going live - but I knew that wouldn't catch all bugs and weird cases.

I was expecting slippage issues, but I couldn't foresee much else going wrong.

The bot was getting good results in backtesting, and it was doing well in the simulated trading environment, so I let it loose in the wild.

And it performed poorly.

But if I re-ran the bot at the end of a poor performing day, in backtesting mode, it would do well. In other words, it wasn't making the same trades in real life as it thought it would make on paper. And slippage wasn't the issue.

Shorting Errors

Turns out my bot made most of its money, on paper, by shorting stocks that were going down. But in the real world, when my bot tried this, it wouldn't be able to enter the trade as there were no shares available to short. And this makes sense – the companies that tank the most are the ones that have a good reason to tank the most, and therefore everyone already knows about it, and therefore there are no shares available to short.

What the heck are shares available to short? Well, now that the $GME fiasco has happened, I assume everyone under the sun is familiar with this concept, so I won't explain it here. But at the time, it opened my eyes to a bunch more information about stocks; and now I take short interest, available shares to short, short fee rates, and short-sale restricted status into account when I make any trade - whether on the long or short side, and whether the trade's expected to last minutes or weeks.

As for realising that the rest of my bot's strategy was losing money without those short trades - well, the great thing about finding a losing strategy in trading, is you can just flip it, turning it into a profitable strategy 😎

Stock Halts

Part of the reason day trading enticed me was that there's plenty of volatility to ride, without the risk of a crazy event happening overnight – like a bank going bust in the GFC, or a really bad earnings report coming out, or a boat getting stuck in one of the busiest ports in the world.

Little did I know, sometimes stocks just stop trading in the middle of the day. It might be due to volatility rules, or a manual halt by the SEC or the exchange, but whatever the case, it's like a mini-overnight and there's no predicting what will happen when it starts trading again (at least, I haven't found a way yet).

For volatility halts, I've now programmed my bot to keep me out of those. Volatility halts happen when the stock moves more than 10% in 5 minutes, so essentially my bot is constantly moving orders to +/-10% of the stock price so that, if those prices are hit, i'm out right before the stock gets halted.

For manually-induced halts, I don't think there's much I can do about those, except to keep in mind that it can happen and manage risk accordingly.