EDIT your original post, please do not just post the code correctly in a new post.
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
if ((TradeHour==Hour())&&(TradeMinutes==Minute())) bool close = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),10,clrRed);
You must select the order before you can use OrderTicket() etc.
-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor -
bool close = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),10,clrRed);
MT4: You can not use any Trade Functions until you first select an order.
-
if ((TradeHour==Hour())&&(TradeMinutes==Minute()))
What if there is no tick that minute? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles (2006)
No candle if open = close ? - MQL4 programming forum (2010)if( tradeHour*3600+TradeMinutes*60 <= time() ) // if ((TradeHour==Hour())&&(TradeMinutes==Minute()))
Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)
EDIT your original post, please do not just post the code correctly in a new post.
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
You must select the order before you can use OrderTicket() etc.
-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor -
MT4: You can not use any Trade Functions until you first select an order.
- What if there is no tick that minute? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles (2006)
No candle if open = close ? - MQL4 programming forum (2010)Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)
Many thanks William,
Really appreciate your feedback!
And here is the final code, working fine apparently :)
Thanks guys !
if ((TradeHour==Hour())&&(TradeMinutes>=Minute())) // Closing at preefined time for (int i=OrdersTotal()-1; i>=0; i--) { // Closing at preefined time if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) // Closing at preefined time bool close = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),10,clrYellow);} // Closing at preefined time
Watch this:

- 2023.02.23
- www.youtube.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi champs,
This is probably a newbies question and please accept my appologies if it is, but I've been searching for a couple of days now and couldn't find any working code to close all my open orders at a certain time of the day.
Below is an extract of my EA in MT4 and I've tried several pieces of code to close orders, the latest one seemed straight forward but did not work:
Any hint on what is wrong with my code?
Many thanks in advance.
Steve