Any way to close after a time?

 

Hey Guys,

I searched a long time for some examples to close one specified Trade after a specified amount of time. Or in another way, to close this trade at 23:59. Before the new day is beginning. 

Can anybody help me please to code that or is there another way?

Greetings and Thank you! 

 
Jan: I searched a long time for some examples to close one specified Trade after a specified amount of time. Or in another way, to close this trade at 23:59. Before the new day is beginning.

We just went over this this morning (2016.11.23 09:38) Close orders after time - MQL5.community traders' Forum

 
  extern string time_to_close = "23:40";
int time_shift;
bool first_tick_chaked;
datetime TimeLoca;

////////////////////////////////////////////////////////////
void OnTick()
{
if(!first_tick_chaked)
{
first_tick_chaked=true;
EventSetTimer(1);
time_shift=int(TimeLocal()-TimeCurrent());
}

}

////////////////////////////////////////////////////////////
void OnTimer()
{  
TimeLoca=TimeLocal();

if(TimeToString(TimeLoca-time_shift,TIME_MINUTES)==time_to_close) close_all();

  }
Reason: