Right way to calculate Trade Size

 
double margin = AccountInfoDouble(ACCOUNT_BALANCE);
double tickValue = SymbolInfoDouble(pSymbol,SYMBOL_TRADE_TICK_VALUE);

double tradeSize = margin / tickValue;

Initial money: 100,000

SYMBOL_TRADE_TICK_VALUE = 1

SYMBOL_TRADE_TICK_SIZE = 0,00001

Ask Price = 1.11225

Running the code above I'll get a trade size of 100,000 but my broker will not execute my order due to: "Open market order: Error 10019 - There is not enough money to fulfill the request"

So, I know the max trade size is 100000 / 1.11225 = 89.907

My question is: How should I calculate the trade size using the mql5 library?


 

Margin has nothing to do with risk. It is your broker's SL on your account.

  • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
  • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
  • Do NOT use TickValue by itself - DeltaPerLot
  • You must normalize lots properly and check against min and max.
  • You must also check FreeMargin to avoid stop out