Hi!
First post here. I’m coding a 5EMA / 34EMA crossover strategy in MQL4. I have been back testing it for a week trying different things to make it profitable but I always end up with poor profit factors.
Looking at the trades on the chart I’ve came to realize they were not entered properly along with my strategy.
The strategy looks for last hour closing prices EMAs and use it to trigger the crossover.
bool isEmaCrossed()
{
hourlyBigEma=ND(iMA(NULL,PERIOD_H1,bigEmaPeriod,0,MODE_EMA,PRICE_CLOSE,0));
hourlySmallEma=ND(iMA(NULL,PERIOD_H1,smallEmaPeriod,0,MODE_EMA,PRICE_CLOSE,0));
if(isSmallAboveBigEma)
{
if(hourlyBigEma>hourlySmallEma)
{
isSmallAboveBigEma=false;
return true;
}
return false;
}
else
{
if(hourlySmallEma>hourlyBigEma)
{
isSmallAboveBigEma=true;
return true;
}
return false;
}
}
And main method :
void OnTick()
{
if(OrdersTotal()==0)
{
if(isBullMarket())
{
if(isEmaCrossed() && isSmallAboveBigEma)
{
//OP BUY
double price=ND(Ask);
double sl=ND(Ask-200*Point);
double tp= ND(price+takeProfit*Point);
ticketNumber=OrderSend(NULL,OP_BUY,0.01,price,5,sl,tp,NULL,0,TimeCurrent()+expirationTime;
}
}
else
{
if(isEmaCrossed() && !isSmallAboveBigEma)
{
//OP SELL
double price=ND(Bid);
double sl = ND(Bid+200*Point);
double tp = ND(price-takeProfit*Point);
ticketNumber=OrderSend(NULL,OP_SELL,0.01,price,5,sl,tp,NULL,0,TimeCurrent()+expirationTime);
}
}
}
}
Unfortunately I can’t put pictures in the post but imagine the 5EMA crossing 34EMA from the top and then on the next candle (hourly) it triggers a buy order. Obviously it sees that 5EMA is still above 34EMA but why is it triggering a crossover then?
Different timings?
I expect someone to tell me an evidence and then to feel completely dumb.
I hope i’m clear. Big thanks for the help.