if you have the order's ticket number you can find the close time by selecting the order with OrderSelect (using SELECT_BY_TICKET and MODE_HISTORY to check closed orders) and then OrderCloseTime().
Stick this in a datetime variable, add 3 hours to it (3*60*60) and then each start, make it check if TimeCurrent() is >= to that variable.
Well, friendly advice... you must be way better at coding before you risk any money with your EA. I've been studying for nearly half a year and (as you can see from WHRoeder's reply) still not confident to risk real money yet. Best thing is search for CodersGuru's beginners' tutorial, its' really simple and useful and got me started. The next thing is read as much as you can stomach of this: https://book.mql4.com//. Also remember you can press F1 when you select any command in MetaEditor and it shows you exactly how to use it.
Basically, you will open an order with OrderOpen, which returns an integer variable which is the ticket number, so do it like this:
int ticket = OrderOpen(.....blah blah..);
After that, most order commands need you to select the order first so do:
OrderSelect(ticket);
and after that you can use OrderCloseTime which returns a datetime variable, and then add three hours to it. MT4 time counts the seconds, so add 3*60*60:
datetime sleeptime = OrderClose() + 10800;
Like WHR said, it's not that same thing as three hour bars, since the order might have closed in the middle of a bar. iBarShift finds the number of the bar in which OrderClose() is. Maybe that's what you want.
Well, friendly advice... you must be way better at coding before you risk any money with your EA. I've been studying for nearly half a year and (as you can see from WHRoeder's reply) still not confident to risk real money yet. Best thing is search for CodersGuru's beginners' tutorial, its' really simple and useful and got me started. The next thing is read as much as you can stomach of this: https://book.mql4.com//. Also remember you can press F1 when you select any command in MetaEditor and it shows you exactly how to use it.
Basically, you will open an order with OrderOpen, which returns an integer variable which is the ticket number, so do it like this:
After that, most order commands need you to select the order first so do:
and after that you can use OrderCloseTime which returns a datetime variable, and then add three hours to it. MT4 time counts the seconds, so add 3*60*60:
Like WHR said, it's not that same thing as three hour bars, since the order might have closed in the middle of a bar. iBarShift finds the number of the bar in which OrderClose() is. Maybe that's what you want.
Ok, thanks - I've got it - don't worry, I'm not going to risk any money yet - I'm still very much in 'demo mode' and will be for some time to come...
Thanks for your help
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want my ea to wait for three bars after the close of the last trade before opening another one. How do I do this? I can't seem to get access to the close time of the last closed trade. anybody?