Free Margin

 

Hello.

I have a question regarding the AccountFreeMargin() function. Genrally you can open new positions unless the Margin level is >100%, i.e. free margin >0. But many brokers still have a delay between time when the order was sent and time when the order was opened. While the AccountFreeMargin() function returns its value according only to already opened orders, there appears to be a gap in time when you can open whatever you want volume regardless the leverage but the broker will immediately close the trades after open because Free Margin Level < Account Stop Out level. So is there a way to control margin fo already sent ORDERS (not trades) that are not yet executed but the margin will be used for them within some short time for sure (because it is a Market Execution)?

Let's take into account the condition that there're several instruments and several expert advisors. Also they are scalping ones so slow solutions like manual calculation of Free Margin and placing it as a GlobalVariable is not appropriate. Big thanks for further answers.

 
Not only do you have to account for the margin that pending orders will use when triggered, you also have to account for margin used as orders go toward the SL.
You must also check FreeMargin to avoid stop out