Best Approch to calculate the Maxium Lot size

 

Hello,

I am not taking Stop Out Level, Risk Percentage or Stop Loss into the consideration, The maximum lot size i can take in my account with Account Balance.

While calculating the Lot size one major problem is

Forex = 100000 Unit

Gold = 100 Unit

Silver = 1000 or Maybe 5000 Unit

Similarly for Stock, it changes. 


Which method is accurate one? I feel Margin Required will be more accurate but even with Margin requires i find error like "Not Enough Money".


Using Margin Required

double MaxLot_UsingMarginRequired = NormalizeDouble(AccountFreeMargin() / MarketInfo(Symbol(), MODE_MARGINREQUIRED), 2);

Using Mode_LotSize :

double MaxLot_UsingLotSize = NormalizeDouble(((AccountFreeMargin() * AccountLeverage()) / Bid) / (MarketInfo(Symbol(), MODE_LOTSIZE)), 2);

Using TickSize :

double MaxLot_UsingTickSize = NormalizeDouble(((AccountFreeMargin() * AccountLeverage()) / Bid) / (1 / MarketInfo(Symbol(), MODE_TICKSIZE)), 2);

Using Point :

double MaxLot_UsingPoint = NormalizeDouble(((AccountFreeMargin() * AccountLeverage()) / Bid) / (1 / Point), 2);
 

I did not test this. Please check this documentation page.

double maxLots(ENUM_ORDER_TYPE order)
{
   ResetLastError();
   double vol_step=SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
   double lots=SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
   while(AccountFreeMarginCheck(Symbol(),order,lots)>0 && GetLastError()!=134) 
      lots+=vol_step;
   return lots-vol_step;
}