Code for adding a timelimit to a trade?

 

I want to modify a EA so every trade will close at "X" ammount of minutes. how do you recommend going about this? what command would i use to make the program wait (e.g. 5 minutes) and then close position?

maybe Sleep(300000);

what is the command to close a position? 

 

I would suggest doing it from OnTimer() 

You need to loop through your open orders - there are plenty of examples about how to do that if you search the site.

For each open order, you check if TimeCurrent() >= OrderOpenTime() + 300

(300 seconds = 5 minutes)

If so, you close the order using OrderClose()

Reason: