How can i calculate lotsize based on Free Margin?

 
How can i calculate the lot maximum size based on the limits of the free margin?
 

You don't want to. Risk has nothing to do with free margin: Account Balance * percentage = Risk = (OrderOpenPrice - OrderStopLoss)*DIR * DeltaPerLot * OrderLots

In addition, you can't open unless you have enough free margin, but to avoid a margin call (stop out) you must have enough at the most adverse excursion (SL) for ALL open order. See my lotsize

 
is there a simple formula to calculate maximum possible lotsize from account free margin?
 
Take your account equity and divide by the minimum margin requirements for the symbol. It is approximately this. AccountEquity()/MarketInfo(Symbol(),MODE_MARGINREQUIRED) .

Hope this helps
Reason: