when an order closed another order like that open

 

i wrote this code & its work but just one problem:

some time it send 2 or 3 or more order like order closed.

i want just send 1

thanks for helping


void openorderagain()
  {
    for(int d = OrdersHistoryTotal() - 1; d >= 0; d--)
      {
        OrderSelect(d,SELECT_BY_POS,MODE_HISTORY);
        if(OrderSymbol() == Symbol())
          {
            if(TimeCurrent() - OrderCloseTime() == 0)
              {
                int Type = OrderType();
                switch(Type)
                  {
                    case OP_BUY : OrderSend(OrderSymbol(),OP_BUYLIMIT,Size,OrderOpenPrice(),5,0,OrderOpenPrice() + TakeProfit*pt,NULL,0,0,Blue);
                                  break;
                    case OP_SELL: OrderSend(OrderSymbol(),OP_SELLLIMIT,Size,OrderOpenPrice(),5,0,OrderOpenPrice() - TakeProfit*pt,NULL,0,0,Red);
                                  break;
                  }
              } 
          }
      }  
  }
 
if(TimeCurrent() - OrderCloseTime() == 0)

That seems rather specific and may be unreliable, are you sure that's what you want?

Sleep() after placing an order would mean that the above test could not be true

 

Dear Ghasem Mohammadi Nemat Abad

if(TimeCurrent() - OrderCloseTime() == 0)

this part of the code only works for one second, i mean timecurrent AND orderclosetime both calculates time based on 1970.01.01 00:00 how many seconds have passed since (read mq4 about time) so if u do subtraction and u want it to be zero then it will work for one second when the order closes the puff timecurrent goes bigger with 1 , so i think ushould change this part, since what if u dont have internet or the comp just offline for whatever the reason, then it wont open the trade!

hope it helped a bit

Onarius