#include <profile.c>
function run()
{
var AtrLen = 3;
var AtrMult = 2;
var AccelInit = 0.02;
var AccelStep = 0.02;
var AccelMax = 0.2;
var Stp;
static var Accel;
static var Hihi, Lolo;
vars Price = series(priceClose());
vars FastMA = series(SMA(Price, 5));
vars SlowMA = series(SMA(Price, 12));
StartDate = 20140801;
if (is(INITRUN)) {
Accel = AccelInit;
}
if (NumOpenLong + NumPendingLong + NumOpenShort + NumPendingShort == 0) {
if (crossOver(FastMA, SlowMA)) {
exitShort();
enterLong(0, 0, priceLow() - AtrMult*ATR(AtrLen));
Accel = AccelInit;
Hihi = priceHigh();
}
if (crossUnder(FastMA, SlowMA)) {
exitLong();
enterShort(0, 0, priceHigh() + AtrMult*ATR(AtrLen));
Accel = AccelInit;
Lolo = priceLow();
}
}
for(open_trades) {
Stp = 0;
if (TradeIsLong) {
TradeStopLimit = min(priceLow(), TradeStopLimit + Accel*(Hihi-TradeStopLimit));
Stp = TradeStopLimit; //for painting
if (priceHigh() > Hihi) {
Hihi = priceHigh();
Accel = min(AccelMax, Accel+AccelStep);
//printf("\nTradeTime=%d, new Accel=%f",TradeTime, Accel);
}
} else if (TradeIsShort) {
TradeStopLimit = max(priceHigh(), TradeStopLimit - Accel*(TradeStopLimit-Lolo));
Stp = TradeStopLimit; //for painting
if (priceLow() < Lolo) {
Lolo = priceLow();
Accel = min(AccelMax, Accel+AccelStep);
}
}
}
// zoom in a certain date
PlotDate = 20140829; //testing with USDJPY 240min
PlotWidth = 4096;
PlotHeight1 = 800;
ColorEquity = ColorDD = 0;
ColorUp = ColorDn = 0x00AAAAAA;
plot("FastMA",FastMA[0],0,BLACK);
plot("SlowMA",SlowMA[0],0,RED);
if (Stp!=0) {plot("Stp",Stp,DOT,BLUE);}
set(PLOTNOW);
}