close all at specific time

 

'Alo mates

need just lil help, solution how to close all opened and pending at the end of the day

it shloud be like

int start()
{
if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds==Seconds()))

Executor();

}

 int Executor()
 {close all trades???
 }

but I have another function like this in code

I did try to run second one, on by one, but it does not work, just first is executed


pending I should solve with

OrderSend(Symbol(),OP_SELLLIMIT,Lots,Ask,3,Bid-StopLoss*Point,Bid+TakeProfit*Point,"",0,0,CLR_NONE);

there is number to set time expiration, but i have no idea what number i have to write here if I want 24h expiration

thank you for your help

 
if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds==Seconds()))
Will not work if there are no ticks that second - very possible. Try:
datetime now = Timecurrent();  #define HR2400 86400
int      tod = now % HR2400,   // Time of day.
         todClose = TradeHour * 3600 + TradeMinutes * 60 + TradeSeconds; 
if (tod >= todClose) ...
 
WHRoeder:
Will not work if there are no ticks that second - very possible. Try:

exactly it works fine, code looks

extern int  TradeHour=0;
extern int  TradeMinutes=0;
extern int  TradeSeconds=0;

int start()
{
if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds==Seconds()))

Executor();

}

 int Executor()
 {
  OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Bid+TakeProfit*Point,"SEMI-AUTO",0,0,CLR_NONE);
 }
i want to repeat section from int start() but i have no idea
 

FilipZ:

WHRoeder:
Will not work if there are no ticks that second - very possible. Try:

exactly it works fine, code looks

i want to repeat section from int start() but i have no idea

Hi FilipZ,

What WHRoeder meant was "it's very possible that there are no ticks at that second", so you will miss that second. That's why WHRoeder's code there is calculating in seconds and using >= (bigger than) sign.

And to close you need to read this from RaptorUK's https://www.mql5.com/en/forum/139654

  //if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds==Seconds()))
  if (TradeHour==Hour()&& TradeMinutes==Minute())
    {
    Executor();
    }

:D

Reason: