If you are having difficulty finding an edge or need a little guidance where to start then read the following post. Here we give you an example futures trading edge:
We evaluate a mean reversion trading strategy
Second Day Gap Futures Trading Strategy
After i explain what an edge is I often have many traders ask me how to find a edge. 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 of simple repeatable habits of the market.
Many traders understand that markets tend to go to one extreme to another very quickly. Often when there is a big sell-off then after a couple of days we have a tremendous bounce or retracement. This is often due to the fact of market balance, often when markets start dropping fast, the players positions in the market become out of balance. It takes time for markets to ride out the storm and find balance between supply/demand and in the process of finding that balance the market will try to "screw over as many players as possible". Fear and greed is a natural trait in human evolution and is ever present in the futures markets. Even algorithms can suffer from the same problem as ultimately they are still programmed by humans which themselves are trying to capture the inefficiency of that fear and greed.
Creating A Simple Mean Reversion Algorithmic Trading Strategy
Many traders particularly retail traders like Gap trading, they have a fascination with overnight gaps in trading indexes/stocks. It is almost as the collective will of all players in the market for gaps to eventually fill - it becomes a sort of self fulfilling prophecy. There actually reasons why gaps do fill (which i won't get into here) but lets try some ideas to find a system involving gap trading.
One Day Gap Fill
First lets simply program a system and test on futures markets (ES-Emini) to see if there is any edge to gap trading on 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 Eastern Time hours from 09:30 to 16:15 (when cash markets are open) we evaluate any gaps made overnight on GLOBEX. 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 is greater/less than yesterdays close by 10% of yesterdays range (you can try use daily ATR or any other value which represents expected daily range):
if newday and
openingPrice < (ydayClose - (ydayRange*0.1)
GapDown +=1; //counts if there is a gap
GapUp = 1;
So above you see the code to get a gap counter going (we do 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. e.g:
//ENTRY LONG HERE
if marketposition = 0
and time = start of new day
and GapDown >1
buy ("long") 1 contracts next bar at market;
We now put in simple stops and targets. Our target is yesterdays close as gap fill being the target and our stops are simply entry price + yesterdays range (short entries) or entry price - yesterdays range (long entries).
There is other code to assume the gap counters are correct and reset back to 1 every-time a gap is filled. So we backtest this for long and short entries the results we get are as follows:
As can be seen from the results that from 2007 to 2015 we have a losing strategy. Profit factor is the most important metric to use when evaluating the results: it can be seen that Long entries have close to 1 profit factor (even) and that is taking into account slippage and commission.
Obviously we could try different stops and targets and get closer to a profitable strategy but currently i would not pursue this any further because the entry has very little merit so no point expanding and creating filters for a non-expectancy entry.
Turn This Losing Algorithmic Trading Strategy Into A Winning One Using Second Day Gaps Only
A lot of daytrader 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 far less and system will trade infrequently. So lets test the same system but now we only enter if there is a two gaps in a row (either up gap or down gap). We add the following logic into our code:
If there is a gap on a single day and this gap fills at-least 90% of 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 opening of market.
The following is the results of two unfilled gaps in a row using same entry, stops and targets as before. In the first image is an example of some of the trades that were made, second image is the results:
As can be seen the long second day gaps strategy is pretty much flat with profit factor 0.97 including transaction costs but the short second day gap strategy is positive with profit factor 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.
Adding Filters to Our Daytrading Strategy
From the previous example of second day gap 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 what i find is that either the target is too small or stop is too big. So by following the old adage of having lower risk to reward on each trade - i consequently used an Average True Range stop and target and set it so targets were at twice then ATR than stops. So small risk and bigger reward on each trade.
Using a different stop and target rules and modifying the risk ratios we now get the following results:
We can see that both longs and shorts are now profitable. The longs have very small profit factor and 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 bull or bear market, high volatility or low volatility the strategy should still perform. The equity curve and yearly pnl figures are below:
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).
For any new daytrader 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 see that 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 strategy shows some promise and is especially good on the short side we would not continue perusing this strategy or improving it for the following reasons:
The trade sample is too small, we would prefer at-least 250 trades short and long each minimum.
The strategy performs poorly on long side without the 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 2. On on daytrading strategy with number of trades less than 250 long or short you would expect much high profit factor: see the following post for further details:
When the strategy was tested we should have divided our data into at-least 3 different samples - the backtesting done in the manner in this post is biased and incorrect. Please see following post for more details on this: Market Inefficiency
Too see results of a strategy we would trade and one which every daytrader should aim to emulate is our: Serenity Bot
I hope this post proves that you can pretty much test and find an edge in numerous ways - even testing sometimes a silly premise might yield promising unexpected results. Please keep following the blog too see new updates and example edges.