/*
Mean Reversion Strategy
ATR Band - looks similar to BollingerBands, without widening of the bands during spikes in Volatility
Entry: Pending order at the perimeter of the ATR Band
Exit: TP at the middle of the ATR Band
*/
function run()
{
//settings
set(PLOTNOW);
StartDate = 20100101;
EndDate = 20161231;
LookBack = 500;
BarPeriod = 240; //set this to 60, 15 or even 1 to see what I mean
NumWFOCycles = 8;
//PriceSeries
vars Price = series(price());
//Optimization Parameters
var ATR_multi = 1; //optimize(2,1,4,0.2); //optimization disabled
//static parameters
TimeFrame = 240 / BarPeriod; //keep Timeframe for the ATR Bands at H4 at all times
//ATR Bands
vars middle = series(LowPass(Price,10));
vars upperATR = series(LowPass(Price,10)+ATR_multi*ATR(100));
vars lowerATR = series(LowPass(Price,10)-ATR_multi*ATR(100));
//Trendfilter
// vars Trend = series(LowPass(Price,200)); //Trendfilter disabled
//TradeManagement
Stop = 2*ATR(25); //optimize(2, 1, 6, 1)*ATR(25);
TakeProfit = middle[0];
EntryTime = 1;
//TradeLogic
if (true) //(rising(Trend)) Trendfilter disabled
{
Entry = -lowerATR[0];
reverseLong(1);
}
if (true) //(falling(Trend))
{
Entry = -upperATR[0];
reverseShort(1);
}
PlotBars=300;
plot("upperATR",upperATR,MAIN,GREY);
plot("lowerATR",lowerATR,MAIN,GREY);
}