// Strategy template ///////////////////////
function run()
{
set(PARAMETERS|LOGFILE); // generate and use optimized parameters
BarPeriod = 60; // 4 hour bars
LookBack = 500;
StartDate = 2005;
EndDate = 2017; // fixed simulation period
NumWFOCycles = 10; // activate WFO
NumCores = -1; // multicore training
asset("EUR/USD");
if(ReTrain) {
UpdateDays = -1;
SelectWFO = -1;
}
// calculate the buy/sell signal
vars Prices = series(price());
//var RoCValue = ROC(Prices,optimize(100,2,400,2)); // maybe use rate of change of the price or even a bandpass filter instead of the rate of change of moving averag as below???
var RoCValue = ROC(series(SMA(Prices,50)),5);
var RSIValue = RSI(Prices,optimize(2,2,40,1));
// buy and sell
var upperLimit = optimize(1.6,1,10,0.1);
var lowerLimit = -1 * upperLimit;
var RSIoverSold = 30;
var RSIoverBought = 100 - RSIoverSold;
Stop = optimize(1,1,20,1) * ATR(optimize(21,2,200,2)); //
Trail = optimize(1,1,20,1) * ATR(optimize(21,2,200,2)); //
if(RoCValue > upperLimit)
{
//uptrend and look out for RSI oversold
if(RSIValue < RSIoverSold)
enterLong();
}
if(RoCValue < lowerLimit)
{
//downtrend and look out for RSI overbought
if(RSIValue > RSIoverBought)
enterShort();
}
// plot signals and thresholds
PlotWidth = 1600;
PlotHeight1 = 800;
set(PLOTNOW);
}