Download MetaTrader 5

How can I find out (at init() e.g.) that Trade is Allowed (opt are set) even if market is closed or Server is busy?

To add comments, please log in or register
Carl Schreiber
6995
Carl Schreiber  

HI,

How can I find out (at init() e.g.) that trade is allowed (terminal-options are set) even if the server is busy (or market closed?)?

IsTradeAllowed();

Returns true if the Expert Advisor is allowed to trade and trading context is not busy, otherwise returns false.
ydrol
593
ydrol  

This is not an atomic check (subject to race conditions) but how about...


begin function

    repeat a few times or forever

       if  (!IsTradeContextBusy() ) return IsTradeAllowed(); // possible race condition

       wait a bit

    end repeat

    return false;

end function


or a bit neater but might get stuck...


while IsTradeContextBusy()

  wait a bit

end while

return IsTradeAllowed() // still possible race condition if IsTradeContextBusy becomes true at this exact moment
Carl Schreiber
6995
Carl Schreiber  
Well I would have expected a function or a flag which is set by the terminal option!
ydrol
593
ydrol  
gooly:
Well I would have expected a function or a flag which is set by the terminal option!

I suspected as much, but couldn't tell for sure from your post. Isnt there a lot more threads avialable these days, so trade context less likely to be busy anyway? Unless doing high performance stuff, in which case MT4 platform might not be the best option?
To add comments, please log in or register