/*
Mean reversion system by Financial-Hacker.com
http://www.financial-hacker.com/build-better-strategies-part-2-model-based-systems/
*/
#include <profile.c>
function run()
{
StartDate = 20050101;
EndDate = 20101231;
BarPeriod = 1440; // 1 day
BarZone = ET; // SPY is in New York
BarOffset = 15*60 + 50; // set the bar end to 15:50, 10 minutes before the market close
LookBack = 1000;
asset("SPY");
set(PRELOAD|LOGFILE|PLOTNOW);
PlotHeight1 = 800; // height of the chart with results
PlotWidth = 2000;
vars Price = series(price());
vars Filtered = series(HighPass(Price,30));
vars Signal = series(FisherN(Filtered,500));
vars HurstVar = series(Hurst(Price,500));
var Threshold = 1.0;
if(Hurst(Price,500) < 0.5) { // do we have mean reversion?
if(crossUnder(Signal,-Threshold))
reverseLong(1);
else if(crossOver(Signal,Threshold))
reverseShort(1);
}
plot("HurstVar",HurstVar,3,DARKGREEN);
plot("HighPass",Filtered,3,BLUE);
plot("FisherN",Signal,3,BLUE);
}