# MQL5 OrderCalcMargin()

Independent and unofficial. Not affiliated with or endorsed by any broker or platform named here. Educational only: nothing here is advice, and nothing here recommends a broker or a trade.

This is the markdown version of https://openbrokerapi.com/platforms/metatrader-5/functions/mql5-ordercalcmargin, written from the same records as that page.

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.

Works out the margin, in the account's currency, that an order of a given type, symbol, volume and price would need on the account as it stands.

- Function: `OrderCalcMargin()`
- Interface: MQL5
- Group: Sending orders
- Status: verified. Source: [mql5.com](https://www.mql5.com/en/docs/trading/ordercalcmargin), checked 2026-10-12.

This is an MQL5 function, not an HTTP endpoint. It has no method, no path and no address to send a request to: it runs inside the MetaTrader 5 terminal, in a program written in MQL5. It is in no OpenAPI file on this site and the request builder does not list it.

## Signature

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

```mql5
bool OrderCalcMargin(
  ENUM_ORDER_TYPE action,
  string symbol,
  double volume,
  double price,
  double& margin
)
```

## Arguments

- `action` (type ENUM_ORDER_TYPE, required): The order type, as a value of the ENUM_ORDER_TYPE enumeration.
- `symbol` (type string, required): The symbol's name.
- `volume` (type double, required): The volume of the trade.
- `price` (type double, required): The opening price.
- `margin` (type double&, required): The variable that receives the margin when the function succeeds. The page says the sum is done as if the account had no pending orders and no open positions.

## Return value

- Type: `bool`
- What comes back: True on success, false otherwise. On failure the page points to GetLastError() for the reason.

## 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.

```mql5
void OnStart()
  {
   double margin=0.0;
   double price=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   if(OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.1,price,margin))
      PrintFormat("margin for 0.1 lots: %.2f",margin);
   else
      PrintFormat("OrderCalcMargin error %d",GetLastError());
  }
```

## Related MQL5 functions: Sending orders

- [OrderCalcProfit()](https://openbrokerapi.com/platforms/metatrader-5/functions/mql5-ordercalcprofit): Works out the profit or loss, in the account's currency, of a trade opened at one price and closed at another, on the account and market as they stand.
- [OrderCheck()](https://openbrokerapi.com/platforms/metatrader-5/functions/mql5-ordercheck): Checks whether there is enough money for a trade request without sending it, and writes what the account would look like into a result structure.
- [OrderSend()](https://openbrokerapi.com/platforms/metatrader-5/functions/mql5-ordersend): Sends a trade request to the trade server and waits for its answer. One function covers a market order, a pending order, a change, a cancellation and a close: the action field of the request says which.
- [OrderSendAsync()](https://openbrokerapi.com/platforms/metatrader-5/functions/mql5-ordersendasync): Sends a trade request to the trade server without waiting for its answer. The page describes it as made for high frequency trading, where waiting for the server is not acceptable.

## More on MetaTrader 5

- [All MetaTrader 5 functions](https://openbrokerapi.com/platforms/metatrader-5/functions): 78 documented here, grouped by what they do.
- [Preview an order: the call at each API](https://openbrokerapi.com/endpoints/order-preview): The same job at every broker and platform API recorded here, HTTP or not.
- [MetaTrader 5 API quickstart](https://openbrokerapi.com/platforms/metatrader-5/quickstart)
- [All MetaTrader 5 error codes](https://openbrokerapi.com/errors/mt5)
- [MetaTrader 5 API page](https://openbrokerapi.com/platforms/metatrader-5): The full record: access, authentication, limits and the source for each.

## Licence and how to cite

The records behind this page are all rights reserved. This file is the page itself, at its own address, in another format. It is not part of the CC BY 4.0 downloads listed at https://openbrokerapi.com/data. Quote from it with a link to the page.

Cite as: MQL5 OrderCalcMargin(). Broker API Hub, https://openbrokerapi.com/platforms/metatrader-5/functions/mql5-ordercalcmargin, newest check 2026-10-12.

Where you rely on a single figure, cite the source and the checked date printed beside it as well. Where this page and a broker's own documentation differ, the documentation wins.
