Download MetaTrader 5
To add comments, please log in or register
Why to sell products in MetaTrader AppStore? Find that out from the article!
Carl Schreiber
5962
Carl Schreiber 2014.03.17 10:41 

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
595
ydrol 2014.03.17 11:05  

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
5962
Carl Schreiber 2014.03.17 14:50  
Well I would have expected a function or a flag which is set by the terminal option!
ydrol
595
ydrol 2014.03.17 14:54  
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