How to close an open position after a certain time?

To add comments, please log in or register
manuzrp
10
manuzrp  

Hi,

I just started coding for MT5. I am able to open a position, close it through take profit and stop loss, but I can't seem to get the code to close the open position if, say, it is after 5.00pm.

Are there any suggestions I may be aware of? Or could you simply let me know how an open position can be closed after a certain time?

Many thanks in advance,

Yohana Parmi
4957
Yohana Parmi  
manuzrp:

Hi,

I just started coding for MT5. I am able to open a position, close it through take profit and stop loss, but I can't seem to get the code to close the open position if, say, it is after 5.00pm.

Are there any suggestions I may be aware of? Or could you simply let me know how an open position can be closed after a certain time?

Many thanks in advance,

Hi,

You can use this way.
Happy coding :)

whroeder1
17944
whroeder1  
manuzrp: but I can't seem to get the code to close the open position if, say, it is after 5.00pm.
Why not? You know the current time (and when the position was opened.) What's your problem?
Nikolai Semko
4751
Nikolai Semko  
manuzrp:

Hi,

I just started coding for MT5. I am able to open a position, close it through take profit and stop loss, but I can't seem to get the code to close the open position if, say, it is after 5.00pm.

Are there any suggestions I may be aware of? Or could you simply let me know how an open position can be closed after a certain time?

Many thanks in advance,

What difficulties?

#include <Trade\Trade.mqh>

...

CTrade trade;
...
MqlDateTime time;
TimeCurrent(time);
if (time.day_of_week==5 && time.hour>=17 && time.min>=15) trade.PositionClose(...);
To add comments, please log in or register