Broker API HubMenu

MQL4 AccountFreeMarginCheck()

functionAccountFreeMarginCheck()MQL4Account

Returns the free margin that would be left after opening an order of a given symbol, direction and size at the current price.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

Independent and unofficialdocs.mql4.comchecked

This is an MQL4 function, not an HTTP endpoint. It has no method, no path and no address to send a request to: it runs inside the MetaTrader 4 terminal, in a program written in MQL4.

Signature

The form of the call on the vendor's page, with the vendor's comments taken out.

double AccountFreeMarginCheck(
  string symbol,
  int cmd,
  double volume
)

Arguments

NameTypeDescription
symbolrequiredstringThe symbol of the trade.
cmdrequiredintThe direction: OP_BUY or OP_SELL.
volumerequireddoubleThe number of lots.

Return value

Type
double
What comes back
The free margin that would remain. The page says error 134, ERR_NOT_ENOUGH_MONEY, is raised when it would not be enough.

Sample

Written by this site from the signature and arguments recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. It holds no credential and needs none: the program runs inside a terminal that is already logged in to an account. Nothing is entered on this site.

void OnStart()
  {
   double left=AccountFreeMarginCheck(Symbol(),OP_BUY,0.1);
   if(left<=0 || GetLastError()==134)
      Print("Not enough free margin for 0.1 lots.");
   else
      Print("Free margin after the trade: ",left);
  }