Posted By: NightWalker
Strategy of peak and valleys optimized for 3 parameters - 12/14/12 13:58
Below you can find unefficient (of course) strategy which optimizes three parameters for M1 period:
- stop loss,
- take profit and
- period for which used ATR is calculated.
- stop loss,
- take profit and
- period for which used ATR is calculated.
Code:
// Strategy which opens random position with optimized take profit and stop loss for optimized period. Used walk forward optimization, parameters explained below. // author: NightWalker @ Zorro Trader Forum // version: 20121214. function run() { BarPeriod = 1; set(PARAMETERS); DataSplit = 90; // 90% training, 10% test NumWFOCycles = 10; // 10 cycles, 9 test periods //parameters to optimization var atrStop = optimize(1,1,1000,20,0); //multiplier of ATR from optimized period for stop loss var atrProfit = optimize(1,1,1000,20,0); //multiplier of ATR from optimized period for take profit var atrPeriod = optimize(1,1,1440,20,0); //period var *closePriceSeries = series(priceClose()); // calculate stop loss and take profit Stop = atrStop*ATR(atrPeriod); TakeProfit = atrProfit*ATR(atrPeriod); Lots = 1; // open only 1 transcation at time and wait until take profit or stop loss is hit if(NumOpenTotal == 0) { if(peak(closePriceSeries)) //on local max enterShort(); else if(valley(closePriceSeries)) // on local min enterLong(); } set(PLOTNOW); PlotWidth = 800; PlotHeight1 = 320; }