EA opens new pending after expiracion ? help

 

Hi ! 

If i could get anyone help, that could be of great help! 

I am getting orders as soon as the right parameters are met but as soon as the pending order that is getting sent gets expired, it opens straight away another one in the same location? 

instead of waiting for the next signal.. please some help here 

if (!Checkifopenorders(magic))
   {  
   if (High[1]<High[2] && Low[1]>Low[2] && MA50>MA200) //BUY-ORDER
      {
      OrderID = OrderSend(NULL,OP_BUYSTOP,PosizeBuy,PrevBarHigh+CurrentSpread,2,PrevBarLow-CurrentSpread,0,"Buy Order",magic,Time[0]+Period()*60);
      Alert ("OrderID" + OrderID);
      if (OrderID<0)
      Alert("Error: "+GetLastError());
      }
   
   else if(High[1]<High[2] && Low[1]>Low[2] && MA50<MA200) //SELL-ORDER
      {
      OrderID = OrderSend(NULL,OP_SELLSTOP,PosizeBuy,PrevBarLow-CurrentSpread,2,PrevBarHigh+CurrentSpread,0,"Sell Order",magic,Time[0]+Period()*60);
      Alert ("OrderID" + OrderID);
      if (OrderID<0)
      Alert("Error: "+GetLastError());
      }
      
   }

/// the function Checkifopenorders(magic)

bool Checkifopenorders(int magic)
{
int openOrders = OrdersTotal();
   for(int i=0;i<openOrders;i++)
   {
      if (OrderSelect(i,SELECT_BY_POS) == true)
    {
      if (OrderMagicNumber() == magic && OrderSymbol()==Symbol())
      return true;
    }
   }   
return false;     
}

 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
JonathanPepperstone: instead of waiting for the next signal..

You are looking at a signal. Act on a change of signal.
          MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12