#include <profile.c>
#define PROFILEDEPTH 30
function run()
{
int fastlen = slider(1, 12, 8, 14, "FastMA", "FastMA");
int slowlen = slider(2, 26, 16, 32, "SlowMA", "SlowMA");
int signallen = slider(3, 9, 7, 11, "SignalMA", "SignalMA");
vars Price = series(priceClose());
vars FastMA = series(EMA(Price,fastlen));
vars SlowMA = series(EMA(Price,slowlen));
vars Macd = series(FastMA[0] - SlowMA[0]);
vars MacdSignal = series(EMA(Macd, signallen));
static int pbctr; //pullback counter
StartDate = 20130501;
Hedge = 2; //enter and open long and short positions simultaneously
if (is(INITRUN)) {
pbctr = 0;
}
for (open_trades) {
if (TradeTime > PROFILEDEPTH) {
exitTrade(ThisTrade);
}
}
if (crossOver(MacdSignal, 0) || crossUnder(MacdSignal, 0)) {
pbctr = 0;
}
if ((MacdSignal[0] > 0) && crossUnder(Macd, MacdSignal)) {
pbctr++;
if (pbctr <= 1) {
plotPriceProfile(PROFILEDEPTH, 0);
enterLong();
}
}
if ((MacdSignal[0] < 0) && crossOver(Macd, MacdSignal)) {
pbctr++;
if (pbctr <= 1) {
plotPriceProfile(PROFILEDEPTH, 2);
enterShort();
}
}
}