- There is no function called “CurrentTime” in MT4/5. Do not post code that will not even compile!
- Time is in seconds; so your “???” should be 3600 (hour).
-
You return false if the latest history entry is older than your “closetime.” Finish the loop, then return false.
Do not assume history is ordered by date, it's not.
Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum (2012)
Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 (2020.06.08) -
Do not assume history has only closed orders.
OrderType() == 6, 7 in the history pool? - MQL4 programming forum (2017) -
Avoid using negative logic (if(x)continue. Simplify
for(int i=OrdersHistoryTotal()-1; i>=0; i--) if( OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && OrderMagicNumber() == magic_no && OrderType() <= OP_SELL // № 4 && OrderCloseTime() >= closetime && OrderSymbol() == _Symbol // Last: string comparisons are slowest. ){ return true; }

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
Hi, I need your idea.
I want to check if there is orders which closed withing 2hours from current time.
If there is closed order within 2hours = true.
If there is no closed order within 2hours = false.
My code
Thank you for your tips!