Please review documentation ... Documentation on MQL5: MQL5 programs / Program Running → Functions prohibited in Indicators and Expert Advisors
The following functions are prohibited in indicators:
To implement your own functions, look into the following symbol property ...
SYMBOL_TRADE_CALC_MODE
Contract price calculation mode
The ENUM_SYMBOL_CALC_MODE enumeration is used for obtaining information about how the margin requirements for a symbol are calculated.
Identifier
Description
Formula
SYMBOL_CALC_MODE_FOREX
Forex mode - calculation of profit and margin for Forex
Margin: Lots * Contract_Size / Leverage * Margin_Rate
Profit: (close_price - open_price) * Contract_Size*Lots
SYMBOL_CALC_MODE_FOREX_NO_LEVERAGE
Forex No Leverage mode – calculation of profit and margin for Forex symbols without taking into account the leverage
Margin: Lots * Contract_Size * Margin_Rate
Profit: (close_price - open_price) * Contract_Size * Lots
SYMBOL_CALC_MODE_FUTURES
Futures mode - calculation of margin and profit for futures
Margin: Lots * InitialMargin * Margin_Rate
Profit: (close_price - open_price) * TickPrice / TickSize*Lots
SYMBOL_CALC_MODE_CFD
CFD mode - calculation of margin and profit for CFD
Margin: Lots * ContractSize * MarketPrice * Margin_Rate
Profit: (close_price - open_price) * Contract_Size * Lots
SYMBOL_CALC_MODE_CFDINDEX
CFD index mode - calculation of margin and profit for CFD by indexes
Margin: (Lots * ContractSize * MarketPrice) * TickPrice / TickSize * Margin_Rate
Profit: (close_price - open_price) * Contract_Size * Lots
SYMBOL_CALC_MODE_CFDLEVERAGE
CFD Leverage mode - calculation of margin and profit for CFD at leverage trading
Margin: (Lots * ContractSize * MarketPrice) / Leverage * Margin_Rate
Profit: (close_price-open_price) * Contract_Size * Lots
SYMBOL_CALC_MODE_EXCH_STOCKS
Exchange mode – calculation of margin and profit for trading securities on a stock exchange
Margin: Lots * ContractSize * LastPrice * Margin_Rate
Profit: (close_price - open_price) * Contract_Size * Lots
SYMBOL_CALC_MODE_EXCH_FUTURES
Futures mode – calculation of margin and profit for trading futures contracts on a stock exchange
Margin: Lots * InitialMargin * Margin_Rate or Lots * MaintenanceMargin * Margin_Rate
Profit: (close_price - open_price) * Lots * TickPrice / TickSize
SYMBOL_CALC_MODE_EXCH_FUTURES_FORTS
FORTS Futures mode – calculation of margin and profit for trading futures contracts on FORTS. The margin may be reduced by the amount of MarginDiscount deviation according to the following rules:
1. If the price of a long position (buy order) is less than the estimated price, MarginDiscount = Lots*((PriceSettle-PriceOrder)*TickPrice/TickSize)
2. If the price of a short position (sell order) exceeds the estimated price, MarginDiscount = Lots*((PriceOrder-PriceSettle)*TickPrice/TickSize)
where:
- PriceSettle – estimated (clearing) price of the previous session;
- PriceOrder – average weighted position price or open price set in the order (request);
- TickPrice – tick price (cost of the price change by one point)
- TickSize – tick size (minimum price change step)
Margin: Lots * InitialMargin * Margin_Rate or Lots * MaintenanceMargin * Margin_Rate
Profit: (close_price - open_price) * Lots * TickPrice / TickSize
SYMBOL_CALC_MODE_EXCH_BONDS
Exchange Bonds mode – calculation of margin and profit for trading bonds on a stock exchange
Margin: Lots * ContractSize * FaceValue * open_price * /100
Profit: Lots * close_price * FaceValue * Contract_Size + AccruedInterest * Lots * ContractSize
SYMBOL_CALC_MODE_EXCH_STOCKS_MOEX
Exchange MOEX Stocks mode – calculation of margin and profit for trading securities on MOEX
Margin: Lots * ContractSize * LastPrice * Margin_Rate
Profit: (close_price - open_price) * Contract_Size * Lots
SYMBOL_CALC_MODE_EXCH_BONDS_MOEX
Exchange MOEX Bonds mode – calculation of margin and profit for trading bonds on MOEX
Margin: Lots * ContractSize * FaceValue * open_price * /100
Profit: Lots * close_price * FaceValue * Contract_Size + AccruedInterest * Lots * ContractSize
SYMBOL_CALC_MODE_SERV_COLLATERAL
Collateral mode - a symbol is used as a non-tradable asset on a trading account. The market value of an open position is calculated based on the volume, current market price, contract size and liquidity ratio. The value is included into Assets, which are added to Equity. Open positions of such symbols increase the Free Margin amount and are used as additional margin (collateral) for open positions of tradable instruments.
Margin: no
Profit: no
Market Value: Lots*ContractSize*MarketPrice*LiqudityRate
- www.mql5.com
Let's say we want to calculate margin for cfd Dax40
I suppose this is how to get parameters:
Lots=1; ContractSize = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_CONTRACT_SIZE);
MarketPrice = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
Margin_Rate is obtained by:
OrderCalcMargin(ORDER_TYPE_BUY, _Symbol, Lots, MarketPrice, Margin_Rate);
But for Leverage :
Leverage=AccountInfoInteger(ACCOUNT_LEVERAGE);
only gives account leverage (which is 30)
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hello,
The instruction
OrderCalcMargin()works perfectly when written in script
But when used in an indicator we got Error n° 4014
ERR_FUNCTION_NOT_ALLOWED
Is this instruction works on script but not in indicator
regards