Hi, I have been programming some eas with lowpass that catch for instance trends of 2 month length or 1 month length. But I found that strategies that succeed in backtests for instance EUR/USD in 2009-2014 fail miserably in 2002-2008.
Is there a way to adapt the moving average period to the market conditions? Thanks!
How to adapt lowpass/moving averages periods to the market?
-
Mithrandir777
- Posts: 4
- Joined: Thu Sep 18, 2014 4:21 am
-
Cubic
- Trader
- Posts: 22
- Joined: Wed Nov 16, 2011 8:21 am
How to adapt lowpass/moving averages periods to the market?
Nice! Your first post here is a million dollar question
There have been a number of attempts to use market conditions to adjust indicator parameter values on the fly:
-The Vidya (Volatility Index Dynamic Average) indicator is an exponential moving average that uses market volatility to alter the M.A.'s length,
-The Kaufman Adaptive Moving Average uses Kaufman's Efficiency Ratio to adjust the M.A.,
-The Mesa Adaptive Moving Average and other efforts have attempted to identify and use the dominant frequencies in the price waveform to adjust the M.A. length,
-Then you have self-correcting Kalman filters: http://en.wikipedia.org/wiki/Kalman_filter ...,
the Ehlers' Fractal Adaptive Moving Average, Russian work with "digital filters" rebuilt/customized periodically for the market being traded, and IIRC, I think Mark Jurik might've been adjusting Jurik Moving Average lookback or phase parameters with his Composite Fractal Behavior indicator.
You get the idea... There have been a lot of attempts at this.
Other efforts have been made to alter system rules on the fly, like this: http://www.earnforex.com/forex-e-books/ ... rategy.pdf
...others have opted for frequent re-optimization.
To some extent the answer (assuming that there really is one
) would be affected by the type of system that you are running, the market it is running on, and especially how the average is being used.
This post is barely 'scratching the surface'. I hope some of the Old Hands on this board will chime in on this important question.
There have been a number of attempts to use market conditions to adjust indicator parameter values on the fly:
-The Vidya (Volatility Index Dynamic Average) indicator is an exponential moving average that uses market volatility to alter the M.A.'s length,
-The Kaufman Adaptive Moving Average uses Kaufman's Efficiency Ratio to adjust the M.A.,
-The Mesa Adaptive Moving Average and other efforts have attempted to identify and use the dominant frequencies in the price waveform to adjust the M.A. length,
-Then you have self-correcting Kalman filters: http://en.wikipedia.org/wiki/Kalman_filter ...,
the Ehlers' Fractal Adaptive Moving Average, Russian work with "digital filters" rebuilt/customized periodically for the market being traded, and IIRC, I think Mark Jurik might've been adjusting Jurik Moving Average lookback or phase parameters with his Composite Fractal Behavior indicator.
You get the idea... There have been a lot of attempts at this.
Other efforts have been made to alter system rules on the fly, like this: http://www.earnforex.com/forex-e-books/ ... rategy.pdf
...others have opted for frequent re-optimization.
To some extent the answer (assuming that there really is one
This post is barely 'scratching the surface'. I hope some of the Old Hands on this board will chime in on this important question.
-
Mithrandir777
- Posts: 4
- Joined: Thu Sep 18, 2014 4:21 am
How to adapt lowpass/moving averages periods to the market?
Thanks for your input Cubic, I really appreciate it! And I know it's a difficult question, I don't intend it to have a definite answer but at least some approximation to the problem. I also would appreciate if more members contribute to the discussion
I have tried using MAMA but it produced too many false signals compared to a lowpass filter. Another approach I found now -instead of rearranging the signal according to market conditions- is to filter the signals when the market has low volatility, for example using the Alligator indicator. I'll try to make a Alligator Lowpass filters and report if it gives good results.
I have tried using MAMA but it produced too many false signals compared to a lowpass filter. Another approach I found now -instead of rearranging the signal according to market conditions- is to filter the signals when the market has low volatility, for example using the Alligator indicator. I'll try to make a Alligator Lowpass filters and report if it gives good results.
-
Mithrandir777
- Posts: 4
- Joined: Thu Sep 18, 2014 4:21 am
How to adapt lowpass/moving averages periods to the market?
What are this "Russian work" with digital filters? And what is IIRC ? I didn't find it in google.Cubic » Wed Sep 24, 2014 3:37 am wrote: -Then you have self-correcting Kalman filters: http://en.wikipedia.org/wiki/Kalman_filter ...,
the Ehlers' Fractal Adaptive Moving Average, Russian work with "digital filters" rebuilt/customized periodically for the market being traded, and IIRC, I think Mark Jurik might've been adjusting Jurik Moving Average lookback or phase parameters with his Composite Fractal Behavior indicator.
-
Cubic
- Trader
- Posts: 22
- Joined: Wed Nov 16, 2011 8:21 am
How to adapt lowpass/moving averages periods to the market?
This was something that I saw years ago. It was formerly at http://www.fin-ware.com. I was just surprised to see that it is now an inactive website.What are this "Russian work" with digital filters? And what is IIRC ? I didn't find it in google.
Here's what the site looked like in 2012:
http://web.archive.org/web/201203112058 ... -ware.com/
Many of the site's pages and 2 articles are preserved, but unfortunately the sample download links no longer work.
I did a little digging and it looks like http://finware.ru/ is the new online home for the company behind this tool. I have no affiliation.
~~~~
If I Recall Correctly (abbreviated as "IIRC"
~~~~
I just bumped into this: http://fx.qrz.ru/ and this, http://www.mql5.com/en/articles/32 - however I've only given them a quick skim.
~~~~
You may find this interesting: http://www.forexfactory.com/showthread.php?t=494141
-
Mithrandir777
- Posts: 4
- Joined: Thu Sep 18, 2014 4:21 am
How to adapt lowpass/moving averages periods to the market?
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:
The results and equity curve:
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 .//\...\.
http://postimg.org/image/z3wui0ifz/
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!
Code: Select all
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();
}
}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 .//\...\.
http://postimg.org/image/z3wui0ifz/
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!