I have been trying to advance in coding some trend following systems and using this great contribution from jcl: MMI I found that with EUR/USD in the period going from 2009-2014 it makes 231% AR,Sharpe Ratio 1.14 , UI 5% but from 2002-2008 it 'makes' -9% AR, Sharpe Ratio -0.17 , UI 1960% -that's what I call a stomach-ache- laugh

How can there be so many differences? I have tried using many tools (MAMA, ShannonGain, KAMA, Hurst) to try to adapt to the market conditions or filter out when the market is not trending but didn't have much luck, if you want to look at everything I tried:

Click to reveal..

Code:
// Workshop 4: Trend Trading ///////////////////
#include <profile.c>

var MMI(vars Data,int TimePeriod)
//credits to jcl
{
	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()
{
	//StartDate = 2002;
	//EndDate = 2008;	
	vars Price = series(price());		
	vars Trend = series(LowPass(Price,500));
	//vars Trendindicator = series(KAMA(Trend,500));	
	vars Signals = series(0);
	
	Stop = 4*ATR(100);
/*	
	if(valley(Trend)) {
		Signals[0] = 1;
		if(Sum(Signals+1,4) == 0)  // no signals in the previous 3 bars?
			enterLong();
		exitShort();  // close opposite position
	} else if(peak(Trend)) {
		Signals[0] = 1;
		if(Sum(Signals+1,4) == 0)
			enterShort();
		exitLong();
	}
*/	
	//vars Hursts = series(Hurst(Price,100));
	var HurstExponent = Hurst(Price,100);
/*
	if(HurstExponent > 0.5) {
		if(valley(Trend))
			enterLong();
		else if(peak(Trend))
			enterShort();
	}	else {
		exitShort();
		exitLong();
	}
*/
	
	/*if(valley(Trend)) {
		if(HurstExponent > 5)  // no signals in the previous 3 bars?
			enterLong();
		exitShort();  // close opposite position
	} else if(peak(Trend)) {
		if(HurstExponent > 5)
			enterShort();
		exitLong();
	}*/

	
	vars Meanness = series(MMI(Price,200));
	vars Filter = series(LowPass(Meanness,500));
	
	if( valley(Trend) ){
		exitShort();  // close opposite position
		if(falling(Filter))
			enterLong();
	} else if( peak(Trend) ) {
		exitLong();
		if(falling(Filter))
			enterShort();
	}
	
	
	/*MAMA(Price,0.05,0.05);
	vars MAMAs = series(rMAMA);
	vars FAMAs = series(rFAMA);*/
	
	/*if( crossUnder(FAMAs,MAMAs) ){
		exitShort();  // close opposite position
		if(falling(Filter))
			enterLong();
	} else if( crossOver(FAMAs,MAMAs) ) {
		exitLong();
		if(falling(Filter))
			enterShort();
	}*/
	
	//vars FilterShannon = series(LowPass(series(ShannonGain(Price,500)),500));
	/*vars FilterShannon = series(ShannonGain(Price,500));
	if( valley(Trend) ){
		exitShort();  // close opposite position
		if(crossOver(FilterShannon,0))
			enterLong();
	} else if( peak(Trend) ) {
		exitLong();
		if(crossUnder(FilterShannon,0))
			enterShort();
	}*/
	
	
	/*BBands(Price,30,2,2,MAType_MAMA);
	plot("price",Price[0],MAIN|LINE,BLACK);
	plot("Bollinger1",rRealUpperBand,BAND1,0x000000CC);
  	plot("Bollinger2",rRealLowerBand,BAND2,0x800000FF);
  	plot("Trend",Trend[0],LINE,RED);
  	plot("Filter",Filter[0],NEW|LINE,BLACK);
	plot("Hurst",HurstExponent*100,NEW|LINE,BLACK);
	plot("Shannon",FilterShannon[0],NEW|LINE,BLACK);*/
	
	/*plot("price",Price[0],MAIN|LINE,BLACK);
	plot("lowpass",Trend,LINE,RED);
	plot("kama",kavg,LINE,BLUE);*/
	
	//PlotWidth = 600;
	//PlotHeight1 = 300;
//	plotTradeProfile(50);
	set(LOGFILE); // log all trades
}




So, in addition to solve this issue, I would like to know in general how to adapt a LowPass to the market conditions. I understood in the tutorial that they use 1000 as cutoff to catch the 2-month or more trends, but is there a way to set this according to the market like the way it is done in workshop 5 using DominantPeriod as the cutoff of the HighPass? Actually the code for that part is:

Code:
vars Period = series(DominantPeriod(Price, 30));
var LowPeriod = LowPass(Period, 500);



and again the doubt: why using 500? In this case maybe because it's an example but in designing an -almost at least- parameter free strategy I would like to know if there's a way or some heuristic to choose the cutoff period of the LowPass.

Thanks beforehand!