Exit order based on time lapsed

 
My EA is a scalper. The logic I have of a good scalp works many times, that is the trade is positive.. but sometimes not. I have discovered that when the trade does not complete fast automatically either with my target price or stop loss exit, that means the quote goes on sideway and it is better to exit fast. How would I write the code so that if the trade has not completed after x minutes, it should exit then? Thanks for the help.
 
If TimeCurrent() - OrderOpenTime() > x * 60 close it.
 
WHRoeder:
If TimeCurrent() - OrderOpenTime() > x * 60 close it.

Thank you very much. This look great and elegant. But I am afraid I am really a newbie. I had the EA written professionally and am trying hard at understanding the code (I guess I asked too many questions to the professional that wrote it and he has become reluctant to respond). Do I need to enter a value between the two parentheses? ... How do I code : "close it". And I suppose I place that line within the loop of a trade.

Thanks again.
 

To 'close it' you will need the ticket number and then read . How to close Orders in mql4 Closing and Deleting Orders. Also get used to googling before asking, people are more responsive if they feel you've done some digging ..


Then you will need to put the OrderClose() command in the right place in the code.

If the code already closes its own orders (ie you see 'close' in the order history) then it will be somewhere near an existing call to OrderClose(). If the code closes all orders via sl/tp then you will need to add new code to check the age.

based on the thread so far, you have to be prepared to do some reading on mql4. I suspect this will take a fair amount of time and effort, especially if you are not trying not to divulge your code at the same time.


For a fast solution you want a developer to fix the code for you but they cant do that without seeing the code.

If you want to keep the code private you may have to ask a developer to look at the code and may have to pay them. I suspect after this you will need more tweaks and have more questions!

If you don't want to pay, You could always enter into a private communication with a developer on the condition they don't reveal the code, and maybe they get rights to the EA also. Again this may lead to more questions, and more time.

If you own all the rights to the source code, you could maybe post it somewhere and probably get free feedback from a lot of developers eager to have a peek at a 'professional's work, however the code you paid for will now be 'out there' for others to use/steal/copy! (if it is worth it!)

- however its possible the developer may have rights over parts of the source in which case you cant do this.

 
ydrol:

To 'close it' you will need the ticket number and then read . How to close Orders in mql4 Closing and Deleting Orders. Also get used to googling before asking, people are more responsive if they feel you've done some digging ..


Then you will need to put the OrderClose() command in the right place in the code.

If the code already closes its own orders (ie you see 'close' in the order history) then it will be somewhere near an existing call to OrderClose(). If the code closes all orders via sl/tp then you will need to add new code to check the age.

based on the thread so far, you have to be prepared to do some reading on mql4. I suspect this will take a fair amount of time and effort, especially if you are not trying not to divulge your code at the same time.


For a fast solution you want a developer to fix the code for you but they cant do that without seeing the code.

If you want to keep the code private you may have to ask a developer to look at the code and may have to pay them. I suspect after this you will need more tweaks and have more questions!

If you don't want to pay, You could always enter into a private communication with a developer on the condition they don't reveal the code, and maybe they get rights to the EA also. Again this may lead to more questions, and more time.

If you own all the rights to the source code, you could maybe post it somewhere and probably get free feedback from a lot of developers eager to have a peek at a 'professional's work, however the code you paid for will now be 'out there' for others to use/steal/copy! (if it is worth it!)

- however its possible the developer may have rights over parts of the source in which case you cant do this.

You are very kind with all your suggestions. I will look at the code more closely and read the different pages you indicate. Thanks.
Reason: