How to adapt lowpass or moving averages periods to market conditions?

Hi, I have been programming some eas with lowpass filters that catch for instance trends of 2 month length or 1 month length. But I found that strategies that succeed in backtests for instance in 2009-2014 fail miserably in 2002-2008.
Is there a way to adapt the moving average period to the market conditions? Thanks!

Anyone knows about it or should I elaborate more?

Changing the periodicity of a moving average to achieve greater profitability on historical data is curve fitting and it will lose money in almost all conditions other than those for which it was fitted. Choosing the right periodicity is simply not possible. What you can adapt to conditions is your position size. You can take on larger sizes with closer stops on entry during periods of low volatility. If you are not familiar with the turtle system and Richard Dennis, I would suggest Curtis Faith’s book and Michael Covel’s Complete Turtle Trader book. These mention how Dennis and the turtles used Average True Range (ATR) to measure volatility and to regulate position sizes. I personally use something more simple and raw than ATR, but a good understanding of it will help you tune your trading to given volatility levels. Guard your capital and may the force be with you.

I like what arbitrager said…

Personally, I would not rely on moving averages…I started using them again recently but this time round I only use them as a barometer to assess how my bias on a currency pair measures up on a daily chart against the (simple) moving averages. I use a 25, 50, 100, and 200-day moving average and look at the following:

  1. how the faster mvas cross the slower ones;
  2. the distance and angle between the mvas;
  3. the position of price relative to the 100 and 200-day mva.

Sometimes the mva crossover strategy works a treat; others, the price may perform a textbook bounce off the 100 and/or 200-day mva; sometimes, also, price slicing through the 200-day mva may indeed be a true reversal signal…However, there will be times when these (lagging) indicators may provide you with all the wrong signals, and then , as arbitrager said, the only thing that will matter will be how much you can limit your losses…

Cheers

Here here. I look at the 200-day SMA because crosses of it are looked at by a great many and it can help to identify breaks. But I don’t trade it. Prices can dance along moving averages for days. They can plunge below the sma when it is in an upward slope and rocket above it when it is in a downward slope. The most important price information is pure highs and lows.

I have been busy with studies and work the last weeks. I have added to my script a filter that measures volatility. I could have used ATR but for some reason I found Alligator interesting so here it is the script and the results, the language used is lite-c from the Zorro platform:


function run()
{
//set(PARAMETERS);
StartDate = 2002;
EndDate = 2008;
NumWFOCycles = 10;
LookBack = 2000;
vars Price = series(price());
var period = 500;
vars Trend = series(LowPass(Price,period));

Stop = ATR(100)*4;//optimize(4, 2, 8);

vars Meanness = series(MMI(Price,200));
vars Filter = series(LowPass(Meanness,period));

Alligator(series(MedPrice()));
var diff = FisherN(series(abs(rBlue-rGreen) + abs(rGreen-rRed)),500);
vars diffs = series(diff);
var Threshold = 2.5;//0.1;//1.0;//1.5;//2.5

static bool Filter2;
if (crossOver(diffs,Threshold) or crossUnder(diffs,-Threshold))
Filter2 = true;
if (crossUnder(diffs,Threshold) or crossOver(diffs,-Threshold))
Filter2 = false;

if( valley(Trend) ){
exitShort(); // close opposite position
if(falling(Filter) and Filter2)
enterLong();
} else if( peak(Trend) ) {
exitLong();
if(falling(Filter) and Filter2)
enterShort();
}
}

The results -equity curve in next post-:

Walk-Forward Test Workshop4_2Pc EUR/USD - performance report

Simulation period 01.05.2002-31.12.2008
Test period 30.11.2004-31.12.2008
WFO test cycles 9 x 2742 bars (23 weeks)
Training cycles 10 x 15538 bars (134 weeks)
Monte Carlo cycles 200
Lookback time 2000 bars (17 weeks)
Assumed slippage 10.0 sec
Spread 2.3 pips (roll -0.10/0.04)
Contracts per lot 1000.0

Gross win/loss 117$ / -44$ (+941p)
Average profit 18$/year, 1.48$/month, 0.07$/day
Max drawdown -34$ 47% (MAE -42$ 58%)
Total down time 41% (TAE 9%)
Max down time 68 weeks from Jul 2007
Largest margin 5.00$
Trade volume 17479$ (4278$/year)
Transaction costs -3.02$ spr, 0.10$ slp, -0.88$ rol
Capital required 34$

Number of trades 17 (5/year, 1/week, 1/day)
Percent winning 41%
Max win/loss 42$ / -16$
Avg trade profit 4.28$ 55.4p (+215.8p / -56.9p)
Avg trade slippage 0.01$ 0.1p (+0.6p / -0.3p)
Avg trade bars 151 (+346 / -14)
Max trade bars 542 (4 weeks)
Time in market 10%
Max open trades 1
Max loss streak 6 (uncorrelated 6)

Annual return 52%
Profit factor 2.65 (PRR 1.25)
Sharpe ratio 0.75
Kelly criterion 1.08
R2 coefficient 0.385
Ulcer index 6.0%
Prediction error 125%

Confidence level AR DDMax Capital

10% 103% 14$ 17$
20% 93% 17$ 19$
30% 85% 18$ 21$
40% 82% 20$ 22$
50% 77% 21$ 23$
60% 73% 22$ 24$
70% 67% 25$ 27$
80% 62% 28$ 29$
90% 55% 32$ 33$
95% 50% 36$ 36$
100% 33% 58$ 54$

Portfolio analysis OptF ProF Win/Loss Wgt% Cycles

EUR/USD .166 2.65 7/10 100.0 ./XX//\
EUR/USD:L .169 3.14 5/6 88.4 …///\
EUR/USD:S .147 1.60 2/4 11.6 .//…

As you can see, I used Alligator lines closeness as a measure of volatility, I normalize their differences and when they go out of a threshold (which is higher the less volatile the market is, this threshold can be adapted to market conditions, maybe using equity curve trading for that) I consider it a signal to buy or sell.

This has turned the loser system into a winning one with good Sharpe Ratio for a trend system and an ulcer of 6%. What do you think? Do you think It has any bias or curve fitting? I look forward to hearing your inputs. Thanks!