Problem with Cross Signal as several signals will be emerged in a second

 

Does anyone have same problem after calculate the cross signal for MACD as it will emerge a several signals in a second so that EA will open a several orders at the same time due to these signals. I tried and though many methods such as limit the OrdersTotal & Sleep(90000) etc., but all did't work. Can anyone help to overcome this problem? Thank you!

Pls see the code as below:

int start()
{
string Status="None";

double MACDM0=iMACD("XAUUSD",PERIOD_M15,12,26,9,0,MODE_MAIN,0);
double MACDS0=iMACD("XAUUSD",PERIOD_M15,12,26,9,0,MODE_SIGNAL,0);
double MACDM1=iMACD("XAUUSD",PERIOD_M15,12,26,9,0,MODE_MAIN,1);
double MACDS1=iMACD("XAUUSD",PERIOD_M15,12,26,9,0,MODE_SIGNAL,1);

//MACD Cross
if(MACDM1<MACDS1 && MACDM0>MACDS0 )
   {
   Status="MACD_UpCross";
   }

if(MACDM1>MACDS1 && MACDM0<MACDS0)
   {
   Status="MACD_DownCross";
   }

Print("Trade Signal= ", Status);

//---Open Order

   if(Status=="MACD_UpCross")
      {
      OrderSend(NULL,OP_BUY,0.1,Ask,0,0,0,NULL,0,0,clrNONE);Print("Status= ",Status);
      }

   if(Status=="MACD_DownCross")
      {
      OrderSend(NULL,OP_SELL,0.1,Bid,0,0,0,NULL,0,0,clrNONE);Print("Status= ",Status);
      }
Files:
test_2.JPG  275 kb
test.JPG  181 kb
 

1°)

Candle 0 gives false signals

So it's better to compare closed candles 2 with 1


2°)

Allow   trades only when new candle opens - not on its ticks

 
It’s works! Thank you for your help! You’re the best, Paul =)
Reason: