mean reversion

Building mean-reversion strategies using templates and limit orders

In this simple tutorial we present you a simple approach to setup a builder template that allows you to generate mean-reversion strategies easily. StrategyQuantX can explore millions of possible combinations of a mean-reversion system that can be easily found using its excelent templating system.

What is a mean-reversion strategy

The concept is really simple. Imagine the market price does not move too much for some time and either trends slowly or is choppy and then suddenly a quick sell-off occurs. In such situation traders tend to perceive this situation as an opportunity to buy with a discount and ‘fade’ this market action expecting the market price to return back to its average (mean).

This approach is commonly used across all markets but surprisingly works well with stocks and stock index futures naturally. In our example we try to test the idea using US index futures data for an e-mini contract but as mentioned the concept can be used in any market.

An example It can be clearly seen on the following picture. The market moved slowly higher and then suddenly went sharply down. Once we see the movement we could assume this ‘extreme’ to be temporary and try to buy into the price weakness expecting the market price to go back up.

How to build a mean reversion system in SQ AlgoWizard

To understand following information we assume you are already familiar with ‘SQ templates and randomization’. If not please skip reading this article for a moment and check our article on Strategy templates.

We could move the idea little further and for a situation where market drops we also assume the drop could continue a little lower before it bounces back to the average thus giving us an additional price discount for the long entry. This is a great opportunity to test a buy limit order how it can perform in this setup and whether it can provide some profit opportunity. So let’s define some basic rules and entry conditions.

Entry conditions

It is quite easy to setup a template for this. To keep everything as simple as possible we build the strategy for the long side only while we want StrategyQuantX to build conditions using all available (and enabled) building blocks. We do not want to limit the builder here since we do not know yet what conditions for placing limit order we are going to use. This can be easily achieved using a template with entry conditions as follows:

  1. The last bar size (from High to Low price) needs to be larger than ATR value (average true range) multiplied by a fix number (for example High – Low > 1.5 x ATR)
  2. We also have a bearish bar for a valid signal (Close < Open)
  3. We add a ‘Random condition 1’ so the builder can replace it by any possible entry and the best exit condition (one or more) such as indicators, signals, price action conditions etc. This can serve the purpose of for example ‘filtering’ signals into a trend direction etc.
  4. Finally we want to trigger the buy entry only if there is no existing long position (we are FLAT)

Note the green-colored items that represent blocks that will be randomly generated later by the builder. We want the builder to optimize it for us

That’s it for the entry signal. Now let’s have a look onto the long entry order tab how to setup the buy limit order correctly using the randomization.

Notice the highlighted part where we set the limit price for the buy limit order. You can see we subtract ATR value again multiplied by a fix value from the last bar close. The fix value will be generated later randomly by SQX in the range from 0.5 to 2 using step = 0.1 (0.5, 0.6, 0.7, …, 1.9, 2). We also want to have the order expiration and stop-loss always enabled in the template so we enable this option as well.

Building mean reversion strategies using StrategyQuantX templates

Now the template is basically complete and we can setup a simple build configuration to test how well this can perform.

To test the idea we will be using the data of E-mini S&P 500 index futures contract. You can easily switch to the micro version of this contract (symbol name ET in StrategyQuant Data Manager) with the point value 10 times smaller compared to the mini version.

We use the simplest build config possible since we want StrategyQuantX to generate just a quick prime sample of strategies to see whether this trading approach can provide profitable systems generally. Let’s setup only the essentials:

We also want to see the actual trades that a strategy creates on a price chart so we enable the ‘Store chart data’ option

And finally we want some basic performance metrics set so only profitable strategies are stored into the databank.

When the random generation mode is used you should get first strategies almost immediately after you start the build. Let’s check the best strategy in the first sample whether all works as expected.

We can also see the pseudo code shows a correct strategy logic according to the template setting we used.

And we can check individual trades executions on a chart directly in StrategyQuantX.

Using this basic template you can explore huge amount of possible strategies across forex, stocks and commodities and across all possible timeframes. We do not recommend to test using small timeframes. While the templates provides good results on intraday charts you can also test using daily or weekly timeframes and apply the concept to a broader portfolio of markets.





Newest Most Voted
Inline Feedbacks
View all comments
August 28, 2021 12:53 pm

HI Tomas, thanks for the blog, i am following your instructions 1 by 1, and have few issues.
I completed the template and put builder to work, after 1 million of strategy, there is 0 acepted because no trades filter.
I went back to algo wizard, notice that you have got random(multisignalD,0.5:2:0.1), i can only select randomvalue.
Can you point out what i done wrong or where to look up?

October 9, 2021 6:51 pm

awesome !!!! thank you Tomas !!!

Continue reading