Originally Posted By: jcl
Use the optimize function for this. You'll then get a performance chart as in Workshop 5, which shows you how the lowpass period affects the result. If it's more or less flat, leave it at 500. If it has a clear peak, it's a parameter to be optimized.


Ok, I have used this code for optimization:

Click to reveal..

Code:
var MMI(vars Data,int TimePeriod)
{
	var m = Median(Data,TimePeriod);
	int i, nh=0, nl=0;
	for(i=1; i<TimePeriod; i++) {
		if(Data[i] > m && Data[i] > Data[i-1])
			nl++;
		else if(Data[i] < m && Data[i] < Data[i-1])
			nh++;
	}
	return 100.*(nl+nh)/(TimePeriod-1);
}

function run()
{
	set(PARAMETERS);
	StartDate = 2002;
	EndDate = 2008;	
	//NumWFOCycles = 10;
	LookBack = 3000;
	vars Price = series(price());
	var period = optimize(500,50,3000,50);
	var mmiperiod = optimize(200,50,1200);
	vars Trend = series(LowPass(Price,period));	
	
	Stop = ATR(100)*optimize(4, 2, 8);
	
	vars Meanness = series(MMI(Price,period));
	vars Filter = series(LowPass(Meanness,mmiperiod));	
	
	if( valley(Trend) ){		
		exitShort();  // close opposite position
		if(falling(Filter))
			enterLong();
	} else if( peak(Trend) ) {		
		exitLong();
		if(falling(Filter))
			enterShort();
	}
}




And here are the parameters charts:

Lowpass period (parameter 1):
Click to reveal..



MMI lowpass period (parameter 2):
Click to reveal..



Stop factor (parameter 3):
Click to reveal..




So they are more or less flat except for the lowpass period, is it because it is the first parameter to be optimized and the others were optimized after the first was optimized?

Then I used WFO:
(I simply added NumWFOCycles = 10; after LookBack = 3000; )

and this is the result of the strategy:

Click to reveal..

Walk-Forward Test Workshop4_2Modfied EUR/USD - performance report

Simulation period 01.07.2002-31.12.2008
Test period 06.01.2005-31.12.2008
WFO test cycles 9 x 2674 bars (23 weeks)
Training cycles 10 x 15152 bars (130 weeks)
Monte Carlo cycles 200
Lookback time 3000 bars (25 weeks)
Assumed slippage 10.0 sec
Spread 2.5 pips (roll 0.01/-0.02)
Contracts per lot 1000.0

Gross win/loss 663$ / -428$ (+3282p)
Average profit 59$/year, 4.93$/month, 0.23$/day
Max drawdown -94$ 40% (MAE -102$ 43%)
Total down time 84% (TAE 43%)
Max down time 159 weeks from Mar 2005
Largest margin 5.00$
Trade volume 254213$ (63784$/year)
Transaction costs -48$ spr, -0.27$ slp, -0.27$ rol
Capital required 87$

Number of trades 265 (67/year, 2/week, 1/day)
Percent winning 21%
Max win/loss 100$ / -9.74$
Avg trade profit 0.89$ 12.4p (+167.9p / -28.4p)
Avg trade slippage -0.00$ -0.0p (+0.6p / -0.2p)
Avg trade bars 42 (+138 / -17)
Max trade bars 902 (7 weeks)
Time in market 47%
Max open trades 1
Max loss streak 32 (uncorrelated 26)

Annual return 68%
Profit factor 1.55 (PRR 1.26)
Sharpe ratio 0.85
Kelly criterion 1.05
R2 coefficient 0.000
Ulcer index 21.8%
Prediction error 55%

Confidence level AR DDMax Capital

10% 85% 74$ 69$
20% 76% 84$ 78$
30% 69% 93$ 86$
40% 64% 100$ 92$
50% 61% 107$ 97$
60% 55% 119$ 108$
70% 49% 133$ 120$
80% 43% 152$ 137$
90% 37% 179$ 160$
95% 33% 204$ 182$
100% 24% 273$ 242$

Portfolio analysis OptF ProF Win/Loss Wgt% Cycles

EUR/USD .062 1.55 55/210 100.0 /\\XXXXX/
EUR/USD:L .093 1.69 26/108 60.5 /\\//\///
EUR/USD:S .039 1.42 29/102 39.5 /\\\\/\\/


And the equity curve. What is the meaning of the blue equity curve below zero?



Anyway, It improved but I have some concerns:

-I used a big optimize range which according to the manual can lead to overfitting but how can I narrow the range without knowing a priori where the optimal value? -This is precisely where all the problem started-

-As I asked before, I don't like that blue and red equity curve below 0. What is the meaning of that? Should I worry?

Thanks!