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();
}
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();
}
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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!