SYMBOL_TRADE_CALC_MODE returned values

 

I can't find a clear documentation about the values returned by the SYMBOL_TRADE_CALC_MODE.

Print(SymbolInfoInteger(_Symbol, SYMBOL_TRADE_CALC_MODE));

would result in 0 for forex (I guess), 2 for CFDs.. do you guys have faced a similar situation?

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Leandro Norcini: I can't find a clear documentation about the values returned by the SYMBOL_TRADE_CALC_MODE. would result in 0 for forex (I guess), 2 for CFDs.. do you guys have faced a similar situation?

What do you mean? It is right there in the documentation and it is very clear ... Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties

And please don't use "0" or "2". Use the enumerations (see below) ...

SYMBOL_TRADE_CALC_MODE

Contract price calculation mode

ENUM_SYMBOL_CALC_MODE

ENUM_SYMBOL_CALC_MODE

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 * 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

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Fernando Carreiro #:

What do you mean? It is right there in the documentation and it is very clear ... Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties

And please don't use "0" or "2". Use the enumerations (see below) ...

SYMBOL_TRADE_CALC_MODE

Contract price calculation mode

ENUM_SYMBOL_CALC_MODE

ENUM_SYMBOL_CALC_MODE

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 * 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

Ahhh thank you Fernando now I got it. The function returns a number that I wasn't able to associate to the Identifier and not the identifier itself, that's why I said that the documentation isn't clear.
 
Leandro Norcini #: Ahhh thank you Fernando now I got it. The function returns a number that I wasn't able to associate to the Identifier and not the identifier itself, that's why I said that the documentation isn't clear.

The documentation is quite clear and it states that it returns an enumeration. So you have to typecast it ...

ENUM_SYMBOL_CALC_MODE eCalcMode = (ENUM_SYMBOL_CALC_MODE) SymbolInfoInteger( _Symbol, SYMBOL_TRADE_CALC_MODE );
Print( EnumToString( eCalcMode ) );
 
Fernando Carreiro #: The documentation is quite clear and it states that it returns an enumeration. So you have to typecast it ...

Ooops so dumb 😫
Now I see it clearly, Thank You much!!

 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
#include <Trade\SymbolInfo.mqh>

void OnStart() {
   Print("SYMBOL_CALC_MODE_FOREX = ", SYMBOL_CALC_MODE_FOREX);
   Print("SYMBOL_CALC_MODE_FUTURES = ", SYMBOL_CALC_MODE_FUTURES);
   Print("SYMBOL_CALC_MODE_CFD = ", SYMBOL_CALC_MODE_CFD);
   Print("SYMBOL_CALC_MODE_EXCH_STOCKS = ", SYMBOL_CALC_MODE_EXCH_STOCKS);
}

And here's the result :
2025.05.01 18:54:10.890 test_calcmode (EURUSD,D1) SYMBOL_CALC_MODE_FOREX = 0
2025.05.01 18:54:10.890 test_calcmode (EURUSD,D1) SYMBOL_CALC_MODE_FUTURES = 1
2025.05.01 18:54:10.890 test_calcmode (EURUSD,D1) SYMBOL_CALC_MODE_CFD = 2
2025.05.01 18:54:10.890 test_calcmode (EURUSD,D1) SYMBOL_CALC_MODE_EXCH_STOCKS = 32

It should be something like this ?
  • SYMBOL_CALC_MODE_FOREX = 0 (correct)
  • SYMBOL_CALC_MODE_FUTURES = 1 (incorrect, should be 2)
  • SYMBOL_CALC_MODE_CFD = 2 (incorrect, should be 3)
  • SYMBOL_CALC_MODE_EXCH_STOCKS = 32 (incorrect, should be 6)??

    https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#enum_symbol_calc_mode

  • Version : 5.00 build 4885 - 28 feb 2025

    Thx

    Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
    Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
    • www.mql5.com
    To obtain the current market information there are several functions: SymbolInfoInteger() , SymbolInfoDouble() and SymbolInfoString() . The first...
     
    Florent #:

    It should be something like this ?
  • SYMBOL_CALC_MODE_FOREX = 0 (correct)
  • SYMBOL_CALC_MODE_FUTURES = 1 (incorrect, should be 2)
  • SYMBOL_CALC_MODE_CFD = 2 (incorrect, should be 3)
  • SYMBOL_CALC_MODE_EXCH_STOCKS = 32 (incorrect, should be 6)??

    https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#enum_symbol_calc_mode

  • Version : 5.00 build 4885 - 28 feb 2025

    Thx


    Why?

    It is an ENUM, there is no need to know the underlying value.

    BTW: Format your post properly. Insert code using the code button.
     
    Dominik Egert #:

    Why?

    It is an ENUM, there is no need to know the underlying value.

    BTW: Format your post properly. Insert code using the code button.
    Hello,
    Thank you for your reply and for the comment about the formatting. I have reworded my message with the code button for clarity.

    I understand that `ENUM_SYMBOL_CALC_MODE` is an enumeration and that it is preferable to use the names of the constants (e.g. `SYMBOL_CALC_MODE_FOREX`) rather than their integer values. However, my problem is that the integer values returned by these constants are **incorrect** to what is expected, and this affects the way my script works.

    #include <Trade\SymbolInfo.mqh>
    
    void OnStart() {
       Print("SYMBOL_CALC_MODE_FOREX = ", SYMBOL_CALC_MODE_FOREX);
       Print("SYMBOL_CALC_MODE_FUTURES = ", SYMBOL_CALC_MODE_FUTURES);
       Print("SYMBOL_CALC_MODE_CFD = ", SYMBOL_CALC_MODE_CFD);
       Print("SYMBOL_CALC_MODE_EXCH_STOCKS = ", SYMBOL_CALC_MODE_EXCH_STOCKS);
    }
    Expected values (based on community tests and implicit documentation from https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#enum_symbol_calc_mode :

    This problem causes errors in my script, which uses these constants to map contract types (e.g. "CASH", "STK") to MT5 calculation modes. For example, GetCalcModeFromSecType("CASH") returns 32 instead of 6, which is invalid for ENUM_SYMBOL_CALC_MODE.

    I checked my project and found no redefinition (#define SYMBOL_CALC_MODE_*) in my .mqh or .mq5 files. I use <Trade\SymbolInfo.mqh> without modifications.

    Questions:

    Can you run this script on your MT5 installation and confirm the constant values? Do you get 2, 3, 6 for FUTURES, CFD, EXCH_STOCKS, or the same values as I do (1, 2, 32)?

    Is this a known bug in MT5, or is there an explanation in my environment (e.g. specific build, custom symbols)?

    I'm also seeing unexpected calls to my GetCalcModeFromSecType function with secType = "true". Any ideas on what might be causing this?

    Thanks for your help! I'm ready to provide more details if needed.


    Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
    Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
    • www.mql5.com
    To obtain the current market information there are several functions: SymbolInfoInteger() , SymbolInfoDouble() and SymbolInfoString() . The first...
     
    Leandro Norcini:

    I can't find a clear documentation about the values returned by the SYMBOL_TRADE_CALC_MODE.

    would result in 0 for forex (I guess), 2 for CFDs.. do you guys have faced a similar situation?

    Yes, SYMBOL_TRADE_CALC_MODE returns an ENUM_SYMBOL_CALC_MODE :

    • 0 = SYMBOL_CALC_MODE_FOREX

    • 1 = SYMBOL_CALC_MODE_FUTURES

    • 2 = SYMBOL_CALC_MODE_CFD

    • 3 = SYMBOL_CALC_MODE_CFDINDEX

    • 4 = SYMBOL_CALC_MODE_CFDLEVERAGE

    • 5 = SYMBOL_CALC_MODE_EXCH_STOCKS

    • 6 = SYMBOL_CALC_MODE_EXCH_FUTURES

    • 7 = SYMBOL_CALC_MODE_EXCH_OPTIONS

    • 8 = SYMBOL_CALC_MODE_CFDCRYPTO

    Use EnumToString() for readable output:

    Print(EnumToString((ENUM_SYMBOL_CALC_MODE)SymbolInfoInteger(_Symbol, SYMBOL_TRADE_CALC_MODE)));

     
    Arda Kaya #:

    Yes, SYMBOL_TRADE_CALC_MODE returns an ENUM_SYMBOL_CALC_MODE :

    • 0 = SYMBOL_CALC_MODE_FOREX

    • 1 = SYMBOL_CALC_MODE_FUTURES

    • 2 = SYMBOL_CALC_MODE_CFD

    • 3 = SYMBOL_CALC_MODE_CFDINDEX

    • 4 = SYMBOL_CALC_MODE_CFDLEVERAGE

    • 5 = SYMBOL_CALC_MODE_EXCH_STOCKS

    • 6 = SYMBOL_CALC_MODE_EXCH_FUTURES

    • 7 = SYMBOL_CALC_MODE_EXCH_OPTIONS

    • 8 = SYMBOL_CALC_MODE_CFDCRYPTO

    Use EnumToString() for readable output:

    Print(EnumToString((ENUM_SYMBOL_CALC_MODE)SymbolInfoInteger(_Symbol, SYMBOL_TRADE_CALC_MODE)));

    Thank you @Arda Kayan for the confirmation of the numbers expected.

    But could you please, execute my little script?
    I need this confirmation to finish my code. 
    Depending on whether it's my mt5 environment or a bug in the function, I'll adapt my approach.