Table of Contents
If you are having difficulty finding an edge or need a little guidance on where to start, then read the following post. Here we will evaluate a mean reversion gap algorithmic trading strategy. We will work together on the day trading strategy and find a new perspective to our original hypothesis. To improve our strategy, we will modify the risk to reward on each trade. So let’s start:
1. What Is An Algorithmic Trading Edge?
An edge is a positive expectancy on a given trade, just like a casino has a statistical probability of success on a blackjack hand. Many think an edge is some elusive holy grail or something so complicated only Nobel prize winners have the ability to come up with one. My answer is always the same, “an edge can be super simple or super complicated, it all depends on your style of trading and account size”. The best edges are ones that can expose a true inefficiency in the markets but there are others which work on simple repeatable habits of the market. For information on Finding a Daytrading Edge click this link.
2. Markets Have a Tendency To Mean Revert
Many day traders understand that markets tend to go from one extreme to another very quickly. Often, when there is a big sell-off, after a couple of days we have a tremendous bounce or retracement, which can even occur on the same day. This is due to market balance: when markets start dropping fast, the players’ positions in the market become out of whack. It takes time for markets to ride out the storm and find a balance between supply and demand. In the process of finding that balance, the market will try to “screw over as many players as possible”. Fear and greed are natural traits in human evolution and are ever-present in the futures markets. Even algorithms can suffer from the same problem as ultimately they are still programmed by humans who are trying to capture the inefficiency of that fear and greed.
3. Creating A Simple Mean Reversion Algorithmic Trading Strategy
Many traders, particularly retail traders, like gap trading. They have a fascination with overnight gaps in futures trading. It is almost as if the collective will of all players in the market for gaps to eventually fill – it becomes a sort of self-fulfilling prophecy. There are reasons why gaps do fill (which I won’t get into here), but let’s try some ideas to find a system involving gap trading.
One-Day Gap Fill Algorithmic Trading Strategy
First, let’s simply program an ES trading system (market ES Emini) to see if there is an edge to gap trading with a single-day gap. I am testing this in Multicharts using Esignal data – I have included commission and slippage and we assume our limit orders fill when price trades through. Using regular Emini Central Time hours from 08:30 to 15:15 (when cash markets are open), we evaluate any gaps made overnight on the GLOBEX futures market. A couple of things we need to program into the system:
What constitutes a gap?
- We declare in this case that a gap is considered today’s opening price being greater/less than yesterday’s close by 10% of yesterday’s range (you can try using daily ATR or any other value which represents expected daily range).
- So above you see the code to get a gap counter going (we do a similar thing to get up gaps). So now we enter positions short/long for gap up/gap down. We do this at the opening price as a market order.
- We can now place some simple stops and targets into our ES trading strategy. Our target is yesterday’s close as a gap fill being the target and our stops are simply entry price + yesterday’s range (short entries) or entry price – yesterday’s range (long entries).
- There is further code to assume the gap counters are correct and reset back to 1 every time a gap is filled.
Gap Trading Strategy Results
- The profit factor is the most important metric to use when evaluating the results: it can be seen that long entries have close to a 1 profit factor (even) and that is taking into account slippage and commission.
- We could easily try different stops and targets and get closer to a profitable strategy. However, I would not pursue this any further because the entry has very little merit so there is no point expanding and creating filters for a negative-expectancy entry rule.
4. Turn This Losing Algorithmic Trading Strategy Into A Winning One Using Second Day Gaps Only
A lot of day traders know that even though single gap days fail often, a double gap day on the major indexes will close. The only problem is that the number of trades will be limited and the system will trade infrequently. So let’s test the same system but now we only enter if there are two gaps in a row (either an up gap or down gap with the previous day’s gap remaining unfilled).
We add the following logic to our code:
- If there is a gap on a single day and this gap fills at
least 90% of the gap value, then we presume this gap to be closed and the gap counter to be reset to zero.
- If we have an open unfilled gap up or down yesterday and then today’s open is also a gap up or down – we can enter long/short at the market on the opening of the market.
- As can be seen, the long second-day gaps strategy is pretty much flat with a profit factor of 0.97 including transaction costs but the short second-day gap strategy is positive with a profit factor of 1.4. The only issue is that we only have 182 short trades and 186 long trades for our sample (which is quite low).
This is just one example of trying to find an edge with algorithmic trading. I am simply demonstrating something which an individual trader may have observed and now is testing whether there is any positive expectancy to their hypothesis. Even if something does not work, we can think of other things around the original hypothesis which might work, e.g., in this case, we went for two gap days in a row. When looking for ideas, always try to be creative, especially if you are looking for repeatable patterns or behaviour.
5. Adjusting Targets For Our Day Trading Strategy
From the previous example of the second-day gap strategy results, I find it interesting that the short side made money, so I wanted to test why the long side does not make money. By looking at many of the trades manually, I found that either the target is too small or the stop is too big. So by following the old adage, we implemented targets having a lower risk to higher reward on each trade – I consequently used an Average True Range (ATR) stop and target and set it so targets were at twice the ATR than the stops. We have a small risk and a bigger reward for each trade.
- Using different stop and target rules and modifying the risk ratios, we now get the following results:
- Both longs and shorts are now profitable. The longs have a very small profit factor and the shorts’ profit factor has actually improved and is now 1.69. The number of trades made is the same as before.
- When evaluating a strategy, we aim to have a smooth equity curve – if you do not have this, then that means your strategy cannot perform in multiple market environments. We also want each year to be profitable, either in a bull or bear market, high volatility or low volatility; the strategy should still perform.
- So the equity curve has some sharp drawdowns and is quite jagged but still, the system has been profitable each and every year apart from 2014 (and even then, the loss was very small).
- Adjusting risk to reward for a trading strategy can change performance significantly. Traders must assess what type of stops/targets to be used or whether stops or targets should be used altogether?
6. Conclusion
For any new day trader or potential algorithmic trader, we can see from this post that we can pretty much start with a simple hypothesis and then work on the same hypothesis from a different angle. Then we can examine by modifying risk/reward for the strategy we can change a losing strategy into a winning one. If you wanted to continue with this particular strategy, you could figure out and design filters where you expect this system to fail.
Why We Would Not Trade This Strategy
Even though the filtered second-day gap algorithmic trading strategy shows some promise and is especially good on the short side, we would not continue pursuing this strategy or improving it for the following reasons:
- The backtest trade sample is too small, we would prefer at least 250 trades short and long each minimum.
- The strategy performs poorly on the long side without the new stops/targets – this shows us that the initial edge or entry does not show massive potential or positive expectancy.
- The profit factor is less than 1.8. With a day trading strategy with the number of trades less than 250 long or short, you would expect a much higher profit factor. With our own Intraday Futures Trading Bot, automated trading system: see the performance metrics for strong systems.
- When the strategy was tested, we should have bootstrapped our data and performed both in-sample and out-of-sample testing – the backtesting done in the manner in this post is biased and incorrect.
- To see the results of a strategy we would trade and one which every day trader should aim to emulate, check out our: Intraday Futures Trading Bot
In summary, I hope this post demonstrates that you can pretty much test and find an edge multiple ways – even testing sometimes a silly assumption might yield promising unexpected results. Please keep following our algorithmic trading blog to see new updates and example edges.