function CheckRSI()
{
TimeFrame = 1; //multiplier for BarPeriod, set BarPeriod = 1 then set TimeFrame = x for different timeframes of the same function
vars Close = series(priceClose()); //sets up a price series based on the current asset/TimeFrame (used for indi)
//vars RSIsignal = series(RSI(Close, optimize(14,2,34,2)));
vars RSIsignal = series(RSI(Close, 14)); //create the indicator series (period can be optimised later)
//var RSIthreshHigh = optimize(75,55,100,5);
var RSIthreshHigh = 75; //set an upper threshold (can be optimised later)
//var RSIthreshLow = optimize(25,0,45,5);
var RSIthreshLow = 25; //set an lower threshold (can be optimised later)
//trade decision
if(crossOver(RSIsignal, RSIthreshLow))
reverseShort(1); //close short trades and open a long position
if(crossUnder(RSIsignal, RSIthreshHigh))
reverseLong(1); //close long trades and open a short position
}
//~equivalent to MQL4 OnTick()
function run()
{
//set(PARAMETERS); // generate and use optimized parameters
BarPeriod = 60;
LookBack = 34; //set to the worst case scenario, RSI period is 14 so this is easy for now
StartDate = 2010;
EndDate = 2015;
//NumWFOCycles = 10; // activate WFO
//carry out trade decisions/operations
CheckRSI();
//plot the results
set(LOGFILE);
//PlotWidth = 600;
//PlotHeight1 = 300;
plot("Signal",series(RSI(series(priceClose()), 14)),NEW,RED);
plot("Threshold1",75,0,BLACK);
plot("Threshold2",25,0,BLACK);
set(PLOTNOW);
}