function run(){
BarPeriod = 1440;
LookBack = 500;
set(LOGFILE+TICKS);
StartDate = 2010;
EndDate = 2015;
//while(asset(loop("EUR/USD", "USD/CHF", "USD/JPY", "XAU/USD", "GBP/USD",
// "USD/CAD", "NZD/USD", "AUD/USD", "GBP/JPY", "UKOil", "USD/JPY", "SPX500",
// "XAG/USD", "XAU/USD", "SPX500", "Bund"))){ //
var atr = ATR(80);
Stop = 3.3*atr;
TakeProfit = 0.25*Stop;
vars Price1 = series( price(0) );
vars Trend = series(LowPass(Price1, 500));
var sellPrice, buyPrice, stopPrice, profitPrice;
if(falling(Trend)){
exitLong();
if(NumOpenShort<1){
sellPrice = priceClose(0)+0.9*atr;
stopPrice = sellPrice + Stop;
profitPrice = sellPrice - TakeProfit;
print(TO_LOG, "\n%s: Sell Limit at price %.4f, Stop %.4f, Target %.4f. ", Asset, sellPrice, stopPrice, profitPrice);
print(TO_HTML, "<br>%s: Sell Limit at price %.4f, Stop %.4f, Target %.4f. ", Asset, sellPrice, stopPrice, profitPrice);
enterShort(0, -sellPrice); // Sell Limit
}
}
else if(rising(Trend)){
exitShort();
if(NumOpenLong<1){
var buyPrice = priceClose(0)-0.9*atr;
stopPrice = buyPrice - Stop;
profitPrice = buyPrice + TakeProfit;
print(TO_LOG, "\n%s: Buy Limit at price %.4f, Stop %.4f, Target %.4f. ", Asset, buyPrice, stopPrice, profitPrice);
print(TO_HTML, "<br>%s: Buy Limit at price %.4f, Stop %.4f, Target %.4f. ", Asset, buyPrice, stopPrice, profitPrice);
enterLong(0, -buyPrice); // Buy Limit
}
}
plot("Trend", Trend, 0, GREY);
plot("atr", atr, NEW, BLUE);
//}
}