AFL of the week: Mean Reversion Trading System

All the AFL’s posted in this section till now are Trend following. Recently, we experimented on a Mean Reversion Trading System and got surprised with its accuracy and returns. In this post,we would go through this system and its backtest report on NSE Nifty. First, let’s find out what Mean Reversion system actually is.

Mean Reversion Trading System: Definition and Overview

Mean Reversion systems assume that Stock prices oscillate in a Fixed range bounded by an upper and lower price bands. The price always tends to return to a median level in due course of time. In order to trade such system, Buy order is placed at the lower end of range and Sell order is placed at the higher end of range. Any breakout of this range with good volumes may lead to strong trends and trade should be avoided during that time. Strict stoploss is imperative in order to trade Mean Reversion systems. There are many indicators which can be handy for developing Mean Reversion Trading systems. Examples are Bollinger Bands, Donchian  channels, RSI, CCI etc.

Please visit Trading Tuitions Academy to learn AFL coding and create your own Trading systems.

AFL Overview

Paramter Value
Preferred Timeframe Intraday 5 minute
Indicators Used Bollinger Band, ADX
Buy Condition
  • Current close is greater than Bollinger Band bottom and previous close is less than Bollinger Band bottom.
  • ADX is less than 35 which indicates ranging market
Short Condition
  • Current close is less than Bollinger Band top and previous close is greater than Bollinger Band top.
  • ADX is less than 35 which indicates ranging market.
Sell Condition
  • Stop Loss hit
  • Target Met
  • Close is less than Bollinger Band bottom.
  • Short Condition met
Cover Condition
  • Stop Loss hit
  • Target Met
  • Close is greater than Bollinger Band top.
  • Buy Condition met
Stop Loss 0.5%
Targets 1%
Position Size 150 (fixed)
Initial Equity 200000
Brokerage 100 per order
Margin 10%

AFL Code

Click here to download the AFL code for this system.

AFL Screenshot

Mean Reversion

Backtest Report

 Paramter Value
  Fixed Position Size
Initial Capital  200000
Final Capital 378919.40
Scrip Name NSE Nifty
Backtest Period 14-Jan-2015 to 29-04-2016
Timeframe 5 Minutes
Net Profit % 89.46%
Annual Return % 61.91%
Number of Trades 114
Winning Trade % 32.46%
Average holding Period 25.17 periods
Max consecutive losses 9
Max system % drawdown -10.78%
Max Trade % drawdown -7.95%

This is the best drawdown figures we were able to achieve in the recent past.Download the detailed backtest report here.

Equity Curve

This strategy has a very smooth and linear equity curve with minimum drawdowns. Check it out.


Additional Amibroker settings for backtesting

Goto Symbol–>Information, and specify the lot size and margin requirement. The below screenshot shows lot size of 75 and margin requirement of 10% for NSE Nifty:

Symbol Info_Nifty


All the AFL’s posted in this section are for learning purpose. Trading Tuitions does not necessarily own these AFL’s and we don’t have any intellectual property rights on them. We might copy useful AFL’s from public forums and post it in this section in a presentable format. The intent is not to copy anybody’s work but to share knowledge. If you find any misleading or non-reproducible content then please inform us at support@tradingtuitions.com

Related Posts


  1. If we backtest previous periods, I saw some great loss up to 68%, Can you show us how to backtest if possible ?

    • Hi Harsha,

      Can you please let me know in which period you backtested this system and what is the source of your data?

      • I checked for 2013-14 .. I took the data from the open source. I think it is very similar to the data you provided in your website.. Please check for atleast 3-4 years ..

  2. Dear Sir,
    I have an AFL with exploration function, when I explore it to my NSE futures watch-list, I get both current and past signals for every symbol. I would like to know how to get only the current (or the most recent) signals of every symbols in my watch-list. Kindly advise me what AFL command I should apply.

    Thank you very much.

  3. Dear sir I want to generate 50% return annually with 20% risk. Will this be an ideal strategy to work for long term. Please let me know. Thanks in advance

    • Hi Ramendra,

      I would not recommend Mean-Reversion strategy for long term. Check out for Trend following strategies instead.

      • Thanks a lot sir for your prompt reply. Will you please suggest a strategy as per my requirement. That will be very beneficial for the investor who want to trade in future markets.

  4. The site is very interesting, informative and educative.
    Shall appreciate your guidiance, AND steps to b followed to integrate the AFLS, in AMI BROKER.


  5. Hello,
    which lookback periods have you taken finally for the ADX and the Bollinger Bands, which produce the – truly amazing – results in you backtest report?
    Best regards, Mike

    • Hi Adant,

      THanks for reporting this, the link to download the code is active now

Leave a Reply

Your email address will not be published.