New order loop with mql 4 and mql 5

 

Hi ,

 

I have a script that sends a new order with an indicator . It works like this :

 

 if (OrdersTotal() < 20 )

{

if (Bid < iMACD(NULL,PERIOD_H1,12,26,9,PRICE_CLOSE,0,1) )

{

  OrderSend(Symbol(),OP_SELL,lot,Bid,0,OrderStopLoss,OrderTakeProfit,"1010",40000,0,Orange) ; 

 return ; 

}

 }

But there is a loop and the MT4 keeps sending 20 orders with the same symbol pair . What is it possible to do to avoid the loop ?

The new system is set to send different pairs orders at the same time , but only once . 

I have tried this :

 

  if (OrdersTotal() < 20 )

{

int send01 = 0 ;

 

if (Bid < iMACD(NULL,PERIOD_H1,12,26,9,PRICE_CLOSE,0,1) )

{

if ( send01 == 20 ) { return ; } 

  OrderSend(Symbol(),OP_SELL,lot,Bid,0,OrderStopLoss,OrderTakeProfit,"1010",40000,0,Orange) ; 

 send01 = 20 ;

return ; 

}

 }

 What is it possible to do for the script to check if there is one entered order with the same symbol and to stop sending new orders ?

Most appreciate a new link

Reason: