value = false after certain period of time from opening a trade

 


After opening a trade, I want to set "value = false" if, for example, the current time is 30 seconds away from the order opening time?

I know I should use "OrderOpenTime" and "Seconds" but I am not good at coding time....

a help would be appreciated.

 
The following function would tell whether current server time is a given seconds or more after the opening time stamp of a given trade
boolean isAfter(int ticket,int seconds)
{
    if ( ! OrderSelect( ticket, SELECT_BY_TICKET ) )
        return( false );
    return( TimeCurrent() - OrderOpenTime() >= seconds );
}
 

so, "TimeCurrent() - OrderOpenTime()" gives me, in seconds, the time from opening a trade till now.


do I need to use RefreshRate() function to keep getting the right time.


thanks a lot for the help

 
Yes, both TimeCurrent() and OrderOpenTime() provides timestamps in seconds. As I understand the documentation, TimeCurrent() returns the timestamp of the tick that triggered the EA, which is a server side timestamp, and I'm guessing that the OrderOpenTime() also is a server side timestamp (the documentation doesn't say).

I think you'd only need to use RefreshRate() if your EA takes long time before returning, like if you keep the same invokation active until the 30 seconds have passed. In my thinking, you'd rather let the start() function return after creating the order (but saving the ticket number in a static variable), and then let it be invoked as new ticks arrive. It'd then test at each invokation whether enough time has passed or not.

Come to think of it, 30 seconds isn't a very long time, and maybe the way to go is actually to block the EA (using "Sleep( 30000 )") for that time directly after sucessfullly opening the order. Maybe someone else, with more experience in this topic, might care to comment.
Reason: