Download MetaTrader 5

Any way to close after a time?

To add comments, please log in or register
Jan
175
Jan 2016.11.23 20:23 

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! 

whroeder1
14750
whroeder1 2016.11.23 21:14  
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

eevviill12
10
eevviill12 2016.11.24 00:22  
  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();

  }
To add comments, please log in or register