[Help] Close all orders older than [NUMBER_OF_HOURS]

 

I need to close all orders older than 2 hours. Anyone know how to do this or have anything that could help?

I tried to understand the time function but it is not working, maybe I am calculating/obtaining the time incorrectly.

Any help is welcome. Thank you! =D

 
Use OrderOpenTime(). After the OrderSelect(). The time is calculated in seconds. How many seconds is in 2 hours? Once you find the answer to that. You ask if TimeCurrent() - OrderOpenTime(). is greater than > or = to X.
 

Thank you, ubzen!

It worked! =D

 

Can you write the code for me, please!!!


BlueKnight:

Thank you, ubzen!

It worked! =D

 
xspeculator:

Can you write the code for me, please!!!




Trie to do what Ubzen wrote...

Use OrderOpenTime(). After the OrderSelect(). The time is calculated in seconds. How many seconds is in 2 hours? Once you find the answer to that. You ask if TimeCurrent() - OrderOpenTime(). is greater than > or = to X.

Means use a loop to get through the OrdersTotal()

use OrderSelect()

if TimeCurrent() - OrderOpenTime(). is greater than > or = to X. Close the trade

 
xspeculator:
Can you write the code for me, please!!!
Already answered Closing orders after a specified number of bars - MQL4 forum
Reason: