function run()
{
StartDate = 2003;
EndDate = 2008;
BarPeriod = 30;
LookBack = 60; // Lookback period changed from default 30 to 60 to cater for largest slow period
asset("GBP/USD");
int StepsFast = 10, StepsSlow = 40; // The number of steps the moving MA will make
NumTotalCycles = StepsSlow * StepsFast; // Number of times to run the system
// no trade costs...
Spread = 0;
Slippage = 0;
RollLong = RollShort = 0;
int Fast, Slow;
Fast = 1 + (TotalCycle % StepsFast); // Should return 1 to 10 each 40 times
Slow = 20 + (TotalCycle / StepsFast); // Should increase 20 by 0.1 10 times per 1-10 cycle of Fast increase
vars Price = series(priceClose() ),
FastMA = series(SMA(Price, Fast) ), // replace SMA parameter with current loop control variable value
SlowMA = series(SMA(Price, Slow) ); // replace SMA parameter with current loop control variable value
static var BuyLimit, SellLimit, BuyStop, SellStop;
if(crossOver(FastMA,SlowMA)) {
BuyStop = priceHigh() + 1*PIP;
BuyLimit = priceHigh() + 5*PIP;
}
if(crossUnder(FastMA,SlowMA)) {
SellStop = priceLow() - 1*PIP;
SellLimit = priceLow() - 5*PIP;
}
if(!NumOpenLong && FastMA[0] > SlowMA[0] && Price[0] < BuyLimit)
enterLong(1,BuyStop);
if(!NumOpenShort && FastMA[0] < SlowMA[0] && Price[0] > SellLimit)
enterShort(1,SellStop);
if (is(EXITRUN)){
char line[100];
sprintf(line,
"\n%6d, %6d, %6.2f, %6.2f",
Slow, Fast, WinTotal, LossTotal); // line sent to csv file
file_append("Data\\NetProfit.csv", line);
}
}