Skip to content
All library documents

Adaptive Moving Averages, Regime Changes, and Overfitting Risk

Article Quant Q&A · Author: MithPaul

Summary

The question explores whether a trend-following system’s moving-average period can adapt to changing market conditions, as a stop distance might adapt using volatility. The author compares results for a fixed system across two EUR/USD historical periods, then tests an adaptive moving-average crossover at different candle intervals. The reported performance varies substantially by period and interval, illustrating that an indicator described as adaptive does not guarantee stable results. Changing the interval to improve historical performance may itself introduce curve-fitting risk.

The response suggests researching Kalman filters and Markov switching models as possible ways to model changing conditions or define a moving-average length. It provides no implementation details, model specification, validation procedure, or evidence that these approaches improve the strategy. The figures are the questioner’s backtest results, not independent confirmation, and the document leaves open how to detect a genuine regime change without selecting parameters based on past performance.

Key ideas

  • A moving-average period can be considered as a quantity that adapts to market conditions.
  • The reported crossover results change across historical periods and candle intervals.
  • An adaptive indicator does not by itself prevent unstable performance or curve fitting.
  • Kalman filters and Markov switching models are suggested as research directions.
  • The response does not give a method for validating regime detection or the strategy.

Tags

Full text
# How to adapt a Moving Average period to market conditions?


# How to adapt a Moving Average period to market conditions?












I would like to know if there is some way to adapt the period of a moving average to market conditions like for instance the stop loss can be adapted to market conditions using the average true range. Thanks!

EDIT: As suggested, I add some references and context to my question.

I have a trend following system that in the test period 2009 - 2014, with one hour candles, no parameters to optimize, EUR/USD produces these figures:

```
Max drawdown        -48$ 13% (MAE -74$ 20%)
Number of trades    165 (28/year, 1/week, 1/day)
Percent winning     31%
Annual return       139%
Profit factor       1.99 (PRR 1.56)
Sharpe ratio        0.92
Kelly criterion     0.55
R2 coefficient      0.647
Ulcer index         9.4%
```

However the same system in 2003 - 2008 makes:

```
    Max drawdown        -131$ 158% (MAE -154$ 185%)
    Number of trades    212 (36/year, 1/week, 1/day)
    Percent winning     19%
    Annual return       14%
    Profit factor       1.15 (PRR 0.90)
    Sharpe ratio        0.27
    Kelly criterion     0.39
    R2 coefficient      0.110
    Ulcer index         68.2%
```

So I tried to look for an adaptive moving average that adapts to market conditions, I read among others these two references:

http://www.mesasoftware.com/papers/MAMA.pdf (just in case it goes down) https://books.google.com.uy/books?id=_KjOT1b9bfUC&pg=PA113&lpg=PA113#v=onepage&q&f=false

I have tried to reproduce the method of the first link mith mixed results, I tested with EUR/USD and candles of 8 hours this code, sorry for the length, I hope you bear with me:

```
vars Price = series(price());           
Stop = 2*ATR(100);  
MAMA(Price,0.05,0.5);
vars MAMAs = series(rMAMA);
vars FAMAs = series(rFAMA);

if( crossUnder(FAMAs,MAMAs) ){
    reverseShort(1);//if the Following Adaptive Moving Average crosses under the Mother of Adaptive Moving Averages then I enter long, closing previous short if any
} else if( crossOver(FAMAs,MAMAs) ) {
    reverseLong(1);
}
plot("price",Price[0],MAIN|LINE,BLACK);
plot("Mama",MAMAs,LINE,RED);
plot("Fama",FAMAs,LINE,BLUE);
```

Testing that in 2009 - 2014 gave

```
Max drawdown        -157$ 64% (MAE -159$ 65%)
Number of trades    392 (68/year, 2/week, 1/day)
Percent winning     62%
Annual return       35%
Profit factor       1.15 (PRR 1.00)
Sharpe ratio        0.52
Kelly criterion     0.73
R2 coefficient      0.002
Ulcer index         21.2%
```

But in 2003 - 2008 it gives

```
Max drawdown        -255$ -1396% (MAE -255$ -1397%)
Number of trades    383 (66/year, 2/week, 1/day)
Percent winning     60%
Annual return       -2%
Profit factor       0.99 (PRR 0.85)
Sharpe ratio        -0.02
Kelly criterion     -0.05
R2 coefficient      0.013
Ulcer index         38.7%
```

However if I test in 2003 - 2008 with 4 hour candles the results are

```
Max drawdown        -145$ 67% (MAE -146$ 67%)
Number of trades    790 (134/year, 3/week, 1/day)
Percent winning     61%
Annual return       32%
Profit factor       1.10 (PRR 0.99)
Sharpe ratio        0.50
Kelly criterion     0.71
R2 coefficient      0.415
Ulcer index         23.0%
```

So, even this 'adaptive' moving average needed to be adapted to a different market by adjusting the duration of candles, but I don't know whether this is curve fitting. Is there a way to detect this change in market conditions between 2003 - 2008 and 2009 - 2014 in this test?

## Answer by radvan (score -1)

https://quant.stackexchange.com/a/18772

As it was already mentioned. Try to read about Kalman filter and Markow Switching models. I have even seen some academic papers where authors tried to define MA length based on MSM or KF. Try to google it ...

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.