var lowpass(vars In,int Period)
{
var a = 1./(1+Period);
vars Out = series(In[0],3);
return Out[0] = (a-0.25*a*a)*In[0]
+ 0.5*a*a*In[1]
- (a-0.75*a*a)*In[2]
+ (2-2*a)*Out[1]
- (1-a)*(1-a)*Out[2];
}
function run()
{
EndDate = 20171231; // fixed simulation period
Verbose = 2;
LookBack = 300; // needed for MMI
asset("EUR/USD");
set(LOGFILE,PLOTNOW); // log all trades
vars Prices = series(priceClose());
vars Trends = series(LowPass(Prices,300));
vars Trends = series(lowpass(Prices,300));
vars Trends2 = series(lowpass(Prices,300));
Stop = 30*ATR(100); // very distant stop
vars MMI_Raws = series(MMI(Prices,300));
vars MMI_Smooths = series(LowPass(MMI_Raws,300));
vars MMI_Smooths = series(lowpass(MMI_Raws,300));
if(falling(MMI_Smooths))
{
if(valley(Trends))
enterLong();
else if(peak(Trends))
enterShort();
}
string Row = strf(
"%02i/%02i/%02i %02i:%02i,%.5f,%.5f,%.5f,%.5f,%.5f,%.5f\n",
day(),month(),year()%100,hour(),minute(),
priceO(),priceH(),priceL(),priceC(), Trends[0], Trends2[0]);
if(is(INITRUN))
file_delete("Data\\export.csv");
// Create header row here
// file_append("Data\\export.csv",Row);
else
file_append("Data\\export.csv",Row);
}