// TMF that opens an opposite trade when stopped out,
// and opens a new trade when profit target is reached (Zorro 1.22 and above)
int ReverseAtStop()
{
printf("#\nTick-price=%.8f",priceClose());
if(TradeIsStop) { // stop loss hit?
if(TradeIsShort)
enterLong(ReverseAtStop); // enter opposite trade
else
enterShort(ReverseAtStop);
}
if(TradeIsProfit) { // profit target hit?
if(TradeIsShort)
enterShort(ReverseAtStop); // enter same trade again
else
enterLong(ReverseAtStop);
}
// call the TMF at stop loss / profit target only
return 16;
}
function run()
{
set(LOGFILE);
set(PLOTNOW);
set(TICKS); // normally needed for TMF
Weekend = 3; // don't run TMF at weekend
BarPeriod = 1440;
Stop = 10000*PIP;
TakeProfit = 10000*PIP;
if(Bar == LookBack) // enter the first trade directly at the first bar
enterLong(ReverseAtStop);
}