Why does this trade open?

 
I have altered a template advisor to open buy trades only when the current MACD is > 0 and when the previous MACD < 0 (with a few minor additions). Why would this trade open, when the MACD is clearly below zero? Is the advisor seeing the MACD jump above 0 on another chart period? Can someone advise?

thanks.
 
I guess I might as well include this:

MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
MacdPrevious2=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,2);
MacdPrevious3=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,3);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
SignalPrevious2=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,2);
MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);

// check for long position (BUY) possibility
if(MacdCurrent>0 && MacdPrevious<0 && MacdPrevious2<0)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"macd sample",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
 

Apparently it "jumped" above 0 on this chart.

indicator/signals that use Bar 0 do not give a stable signal

if(MacdCurrent>0 && MacdPrevious<0 && MacdPrevious2<0)

Looks like that condition could have been acheived, opening the trade, even though the final result for that bar
did not conform to the signal requirements.

 

Is there anyway that these "jumps" can be avoided? Is there programming language that could make sure the tester only uses the completed bars? Or would you recognize that I use period 1 instead of period 0 to make sure this doesn't happen?


thanks for your response.

 

Take your signal on the first ticks of the new current bar...

MacdCurrent=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
MacdPrevious=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,2);
MacdPrevious2=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,3);
MacdPrevious3=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,4);
SignalCurrent=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
SignalPrevious=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,2);
SignalPrevious2=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,3);
MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,2);

 
Phy, could I pick your brain? When you create an advisor, do you look at the percentage of winning trades as your barometer? In other words, how do you judge the success of your advisors?
 
Sorry, no success with automation at this time.