Delay before closing all orders

Nargiz Ravanova  

Hi,

I am trying to find the way how to delay my function CloseAll (closing all orders) before it will execute.

So once EA see profit it should pause for couple seconds (let say for 10 sec) and after CloseAll will take place.

here is my part of EA. Could you please advise what to add ?

      double op = CalculateProfit();
      if (op >= Profit  )
      {
           CloseAll();
      SendNotification("Trade is end1");
      Sleep(60*60000);// 60.000 = 1 min
      SendNotification("Trade is end2");
      Sleep(60*60000);// 60.000 = 1 min
      
      }
Documentation on MQL5: Network Functions / SendNotification
Documentation on MQL5: Network Functions / SendNotification
  • www.mql5.com
SendNotification - Network Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
William Roeder  
Nargiz Ravanova: I am trying to find the way how to delay …

Yet you posted code that already has two delays.

Nargiz Ravanova  
William Roeder:

Yet you posted code that already has two delays.

I am talking about before not after.
Nargiz Ravanova  
Kenneth Parling:

As @William Roeder wrote ' Yet you posted code that already has two delays.' Use the delay before execution of CloseAll(). Right now it gets executed instantly if; 

and you don't want that. You want the delay before it happens right....

Sleep before CloseAll() is not working, not sure maybe it is structure of MQL4 otherwise I will not ask for advise.
Nargiz Ravanova  

is this gonna work?

int sec;
void OnTick()
{
//+------------
    double op = CalculateProfit();
      if (op >= Profit  )
      {
sec = Seconds() ;

if (sec >=25)

{       
CloseAll();
      SendNotification("Trade is end1");
      Sleep(60*60000);// 60.000 = 1 min
      SendNotification("Trade is end2");
      Sleep(60*60000);// 60.000 = 1 min
}}
//+----------------
}
Just want to inform that all this testing I am doing for demo account, I guess this should not affect.
William Roeder  
Nargiz Ravanova: Sleep before CloseAll() is not working, not sure maybe it is structure of MQL4 otherwise I will not ask for advise.
  1. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. 2004
              When asking about code

  2. Sleep does not work in the tester.

  3. After Sleep and between server calls the market will have changed. You must update your Predefined Variables or series arrays before using any of them — you must call RefreshRates. RefreshRates updates:
    Predefined variables: Ask, Bars, Bid, Close[], High[], Low[], Open[], Point, Time[], Volume[]
              RefreshRates - Timeseries and Indicators Access - MQL4 Reference
              Predefined Variables - MQL4 Reference
    Also updates: Hour, Minute, and Seconds
              Minute() returns wrong values - or am I wrong? - MQL4 programming forum
Reason: