MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Automated Trading Language Documentation

MPC - Measure Popular Candles Script
MPC - Measure Popular Candles
Author: Aktiniy
Reforce MaximumReforce Maximum Try product
Reforce Maximum
Author: achidayat
Screenshot
NZDUSD., H1
Real
Technical Analysis: What Do We Analyze? Technical Analysis: What Do We Analyze? Subscribe to signal
FOREX NAVIGATOR WWW
211.78%, 20 047.82 USD

Symbol Properties

To obtain the current market information there are several functions: SymbolInfoInteger(), SymbolInfoDouble() and SymbolInfoString(). The first parameter is the symbol name, the values of the second function parameter can be one of the identifiers of ENUM_SYMBOL_INFO_INTEGER, ENUM_SYMBOL_INFO_DOUBLE and ENUM_SYMBOL_INFO_STRING.

For function SymbolInfoInteger()

ENUM_SYMBOL_INFO_INTEGER

Identifier

Description

Type

SYMBOL_SELECT

Symbol is selected in Market Watch

bool

SYMBOL_SESSION_DEALS

Number of deals in the current session

long

SYMBOL_SESSION_BUY_ORDERS

Number of Buy orders at the moment

long

SYMBOL_SESSION_SELL_ORDERS

Number of Sell orders at the moment

long

SYMBOL_VOLUME

Volume of the last deal

long

SYMBOL_VOLUMEHIGH

Maximal day volume

long

SYMBOL_VOLUMELOW

Minimal day volume

long

SYMBOL_TIME

Time of the last quote

datetime

SYMBOL_DIGITS

Digits after a decimal point

int

SYMBOL_SPREAD_FLOAT

Indication of a floating spread

bool

SYMBOL_SPREAD

Spread value in points

int

SYMBOL_TICKS_BOOKDEPTH

Maximal number of requests shown in Depth of Market. For symbols that have no queue of requests, the value is equal to zero.

int

SYMBOL_TRADE_CALC_MODE

Contract price calculation mode

ENUM_SYMBOL_CALC_MODE

SYMBOL_TRADE_MODE

Order execution type

ENUM_SYMBOL_TRADE_MODE

SYMBOL_START_TIME

Date of the symbol trade beginning (usually used for futures)

datetime

SYMBOL_EXPIRATION_TIME

Date of the symbol trade end (usually used for futures)

datetime

SYMBOL_TRADE_STOPS_LEVEL

Minimal indention in points from the current close price to place Stop orders

int

SYMBOL_TRADE_FREEZE_LEVEL

Distance to freeze trade operations in points

int

SYMBOL_TRADE_EXEMODE

Deal execution mode

ENUM_SYMBOL_TRADE_EXECUTION

SYMBOL_SWAP_MODE

Swap calculation model

ENUM_SYMBOL_SWAP_MODE

SYMBOL_SWAP_ROLLOVER3DAYS

Weekday to charge 3 days swap rollover

ENUM_DAY_OF_WEEK

SYMBOL_EXPIRATION_MODE

Flags of allowed order expiration modes

int

SYMBOL_FILLING_MODE

Flags of allowed order filling modes

int

SYMBOL_ORDER_MODE

Flags of allowed order types

int

For function SymbolInfoDouble()

ENUM_SYMBOL_INFO_DOUBLE

Identifier

Description

Type

SYMBOL_BID

Bid - best sell offer

double

SYMBOL_BIDHIGH

Maximal Bid of the day

double

SYMBOL_BIDLOW

Minimal Bid of the day

double

SYMBOL_ASK

Ask - best buy offer

double

SYMBOL_ASKHIGH

Maximal Ask of the day

double

SYMBOL_ASKLOW

Minimal Ask of the day

double

SYMBOL_LAST

Price of the last deal

double

SYMBOL_LASTHIGH

Maximal Last of the day

double

SYMBOL_LASTLOW

Minimal Last of the day

double

SYMBOL_POINT

Symbol point value

double

SYMBOL_TRADE_TICK_VALUE

Value of SYMBOL_TRADE_TICK_VALUE_PROFIT

double

SYMBOL_TRADE_TICK_VALUE_PROFIT

Calculated tick price for a profitable position

double

SYMBOL_TRADE_TICK_VALUE_LOSS

Calculated tick price for a losing position

double

SYMBOL_TRADE_TICK_SIZE

Minimal price change

double

SYMBOL_TRADE_CONTRACT_SIZE

Trade contract size

double

SYMBOL_VOLUME_MIN

Minimal volume for a deal

double

SYMBOL_VOLUME_MAX

Maximal volume for a deal

double

SYMBOL_VOLUME_STEP

Minimal volume change step for deal execution

double

SYMBOL_VOLUME_LIMIT

Maximum allowed aggregate volume of an open position and pending orders in one direction (buy or sell) for the symbol. For example, with the limitation of 5 lots, you can have an open buy position with the volume of 5 lots and place a pending order Sell Limit with the volume of 5 lots. But in this case you cannot place a Buy Limit pending order (since the total volume in one direction will exceed the limitation) or place Sell Limit with the volume more than 5 lots.

double

SYMBOL_SWAP_LONG

Long swap value

double

SYMBOL_SWAP_SHORT

Short swap value

double

SYMBOL_MARGIN_INITIAL

Initial margin means the amount in the margin currency required for opening a position with the volume of one lot. It is used for checking a client's assets when he or she enters the market.

double

SYMBOL_MARGIN_MAINTENANCE

The maintenance margin. If it is set, it sets the margin amount in the margin currency of the symbol, charged from one lot. It is used for checking a client's assets when his/her account state changes. If the maintenance margin is equal to 0, the initial margin is used.

double

SYMBOL_MARGIN_LONG

Rate of margin charging on long positions

double

SYMBOL_MARGIN_SHORT

Rate of margin charging on short positions

double

SYMBOL_MARGIN_LIMIT

Rate of margin charging on Limit orders

double

SYMBOL_MARGIN_STOP

Rate of margin charging on Stop orders

double

SYMBOL_MARGIN_STOPLIMIT

Rate of margin charging on Stop Limit orders

double

SYMBOL_SESSION_VOLUME

Summary volume of current session deals

double

SYMBOL_SESSION_TURNOVER

Summary turnover of the current session

double

SYMBOL_SESSION_INTEREST

Summary open interest

double

SYMBOL_SESSION_BUY_ORDERS_VOLUME

Current volume of Buy orders

double

SYMBOL_SESSION_SELL_ORDERS_VOLUME

Current volume of Sell orders

double

SYMBOL_SESSION_OPEN

Open price of the current session

double

SYMBOL_SESSION_CLOSE

Close price of the current session

double

SYMBOL_SESSION_AW

Average weighted price of the current session

double

SYMBOL_SESSION_PRICE_SETTLEMENT

Settlement price of the current session

double

SYMBOL_SESSION_PRICE_LIMIT_MIN

Minimal price of the current session

double

SYMBOL_SESSION_PRICE_LIMIT_MAX

Maximal price of the current session

double

For function SymbolInfoString()

ENUM_SYMBOL_INFO_STRING

Identifier

Description

Type

SYMBOL_CURRENCY_BASE

Basic currency of a symbol

string

SYMBOL_CURRENCY_PROFIT

Profit currency

string

SYMBOL_CURRENCY_MARGIN

Margin currency

string

SYMBOL_BANK

Feeder of the current quote

string

SYMBOL_DESCRIPTION

Symbol description

string

SYMBOL_ISIN

The name of a symbol in the ISIN system (International Securities Identification Number). The International Securities Identification Number is a 12-digit alphanumeric code that uniquely identifies a security. The presence of this symbol property is determined on the side of a trade server.

string

SYMBOL_PATH

Path in the symbol tree

string

 

For each symbol several expiration modes of pending orders can be specified. A flag is matched to each mode. Flags can be combined using the operation of logical OR (|), for example, SYMBOL_EXPIRATION_GTC|SYMBOL_EXPIRATION_SPECIFIED. In order to check whether a certain mode is allowed for the symbol, the result of the logical AND (&) should be compared to the mode flag.

If flag SYMBOL_EXPIRATION_SPECIFIED is specified for a symbol, then while sending a pending order, you may specify the moment this pending order is valid till.

Identifier

Value

Description

SYMBOL_EXPIRATION_GTC

1

The order is valid during the unlimited time period, until it is explicitly canceled

SYMBOL_EXPIRATION_DAY

2

The order is valid till the end of the day

SYMBOL_EXPIRATION_SPECIFIED

4

The expiration time is specified in the order

SYMBOL_EXPIRATION_SPECIFIED_DAY

8

The expiration date is specified in the order

Example:

//+------------------------------------------------------------------+
//| Checks if the specified expiration mode is allowed               |
//+------------------------------------------------------------------+
bool IsExpirationTypeAllowed(string symbol,int exp_type)
  {
//--- Obtain the value of the property that describes allowed expiration modes
   int expiration=(int)SymbolInfoInteger(symbol,SYMBOL_EXPIRATION_MODE);
//--- Return true, if mode exp_type is allowed
   return((expiration&exp_type)==exp_type);
  }

 

When sending an order, you can specify the filling policy for the volume set in the order. Allowed order filling modes for each symbol are specified in the table. You can set several modes for one symbol by combining flags. The flags can be combined by the operation of the logical OR (|), for example, SYMBOL_FILLING_ALL_OR_NONE|SYMBOL_CANCEL_REMAIND.  In order to check whether a certain mode is allowed for the symbol, the result of the logical AND (&) should be compared to the mode flag.

Identifier

Value

Description

SYMBOL_FILLING_ALL_OR_NONE

1

"All or none". If the volume specified in the order with the specified price cannot be fully filled, the order is canceled and the deal is not conducted

SYMBOL_CANCEL_REMAIND

2

If only part of the specified volume can be filled, the deal for the available volume will be executed. The order remainder is canceled, and the new order is not placed

SYMBOL_RETURN_REMAIND

4

A deal is executed for the available volume. A new order at the same price is set for the remainder

Example:

//+------------------------------------------------------------------+
//| Checks if the specified filling mode is allowed                  |
//+------------------------------------------------------------------+
bool IsFillingTypeAllowed(string symbol,int fill_type)
  {
//--- Obtain the value of the property that describes allowed expiration modes
   int filling=(int)SymbolInfoInteger(symbol,SYMBOL_FILLING_MODE);
//--- Return true, if mode fill_type is allowed
   return((filling & fill_type)==fill_type);
  }

 

When sending a trade request using OrderSend() function, an order type from ENUM_ORDER_TYPE enumeration should be specified for some operations. Not all types of orders may be allowed for a specific symbol. SYMBOL_ORDER_MODE property describes the flags of the allowed order types.

Identifier

Value

Description

SYMBOL_ORDER_MARKET

1

Market orders are allowed (Buy and Sell at the market price without specifying a deal price)

SYMBOL_ORDER_LIMIT

2

Limit orders are allowed (Buy Limit and Sell Limit)

SYMBOL_ORDER_STOP

4

Stop orders are allowed (Buy Stop and Sell Stop)

SYMBOL_ORDER_STOP_LIMIT

8

Stop-limit orders are allowed (Buy Stop Limit and Sell Stop Limit)

SYMBOL_ORDER_SL

16

Stop Loss is allowed

SYMBOL_ORDER_TP

32

Take Profit is allowed

Example:

//+------------------------------------------------------------------+
//| The function prints out order types allowed for a symbol         |
//+------------------------------------------------------------------+
void Check_SYMBOL_ORDER_MODE(string symbol)
  {
//--- receive the value of the property describing allowed order types
   int symbol_order_mode=(int)SymbolInfoInteger(symbol,SYMBOL_ORDER_MODE);
//--- check for market orders (Market Execution)
   if((SYMBOL_ORDER_MARKET&symbol_order_mode)==SYMBOL_ORDER_MARKET)
      Print(symbol+": Market orders are allowed (price specification is not required)");
//--- check for Limit orders
   if((SYMBOL_ORDER_LIMIT&symbol_order_mode)==SYMBOL_ORDER_LIMIT)
      Print(symbol+": Buy Limit and Sell Limit orders are allowed");
//--- check for Stop orders
   if((SYMBOL_ORDER_STOP&symbol_order_mode)==SYMBOL_ORDER_STOP)
      Print(symbol+": Buy Stop and Sell Stop orders are allowed");
//--- check for Stop Limit orders
   if((SYMBOL_ORDER_STOP_LIMIT&symbol_order_mode)==SYMBOL_ORDER_STOP_LIMIT)
      Print(symbol+": Buy Stop Limit and Sell Stop Limit orders are allowed");
//--- check if placing a Stop Loss orders is allowed
   if((SYMBOL_ORDER_SL&symbol_order_mode)==SYMBOL_ORDER_SL)
      Print(symbol+": Stop Loss orders are allowed");
//--- check if placing a Take Profit orders is allowed
   if((SYMBOL_ORDER_TP&symbol_order_mode)==SYMBOL_ORDER_TP)
      Print(symbol+": Take Profit orders are allowed");
//---
  }

 

The ENUM_SYMBOL_CALC_MODE enumeration is used for obtaining information about how the margin requirements for a symbol are calculated.

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

Profit:   (close_price-open_price)*Contract_Size*Lots

SYMBOL_CALC_MODE_FUTURES

Futures mode - calculation of margin and profit for futures

Margin: Lots *InitialMargin*Percentage/100

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*Percentage/100

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

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*Percentage)/Leverage

Profit:  (close_price-open_price)*Contract_Size*Lots

 

There are several symbol trading modes. Information about trading modes of a certain symbol is reflected in the values of enumeration ENUM_SYMBOL_TRADE_MODE.

ENUM_SYMBOL_TRADE_MODE

Identifier

Description

SYMBOL_TRADE_MODE_DISABLED

Trade is disabled for the symbol

SYMBOL_TRADE_MODE_LONGONLY

Allowed only long positions

SYMBOL_TRADE_MODE_SHORTONLY

Allowed only short positions

SYMBOL_TRADE_MODE_CLOSEONLY

Allowed only position close operations

SYMBOL_TRADE_MODE_FULL

No trade restrictions

 

Possible deal execution modes for a certain symbol are defined in enumeration ENUM_SYMBOL_TRADE_EXECUTION.

ENUM_SYMBOL_TRADE_EXECUTION

Identifier

Description

SYMBOL_TRADE_EXECUTION_REQUEST

Execution by request

SYMBOL_TRADE_EXECUTION_INSTANT

Instant execution

SYMBOL_TRADE_EXECUTION_MARKET

Market execution

SYMBOL_TRADE_EXECUTION_EXCHANGE

Exchange execution

 

Methods of swap calculation at position transfer are specified in enumeration ENUM_SYMBOL_SWAP_MODE. The method of swap calculation determines the units of measure of the SYMBOL_SWAP_LONG and SYMBOL_SWAP_SHORT parameters. For example, if swaps are charged in the client deposit currency, then the values of those parameters are specified as an amount of money in the client deposit currency.

ENUM_SYMBOL_SWAP_MODE

Identifier

Description

SYMBOL_SWAP_MODE_DISABLED

Swaps disabled (no swaps)

SYMBOL_SWAP_MODE_POINTS

Swaps are charged in points

SYMBOL_SWAP_MODE_CURRENCY_SYMBOL

Swaps are charged in money in base currency of the symbol

SYMBOL_SWAP_MODE_CURRENCY_MARGIN

Swaps are charged in money in margin currency of the symbol

SYMBOL_SWAP_MODE_CURRENCY_DEPOSIT

Swaps are charged in money, in client deposit currency

SYMBOL_SWAP_MODE_INTEREST_CURRENT

Swaps are charged as the specified annual interest from the instrument price at calculation of swap (standard bank year is 360 days)

SYMBOL_SWAP_MODE_INTEREST_OPEN

Swaps are charged as the specified annual interest from the open price of position (standard bank year is 360 days)

SYMBOL_SWAP_MODE_REOPEN_CURRENT

Swaps are charged by reopening positions. At the end of a trading day the position is closed. Next day it is reopened by the close price +/- specified number of points (parameters SYMBOL_SWAP_LONG and SYMBOL_SWAP_SHORT)

SYMBOL_SWAP_MODE_REOPEN_BID

Swaps are charged by reopening positions. At the end of a trading day the position is closed. Next day it is reopened by the current Bid price +/- specified number of points (parameters SYMBOL_SWAP_LONG and SYMBOL_SWAP_SHORT)

 

Values of the ENUM_DAY_OF_WEEK enumeration are used for specifying weekdays.

ENUM_DAY_OF_WEEK

Identifier

Description

SUNDAY

Sunday

MONDAY

Monday

TUESDAY

Tuesday

WEDNESDAY

Wednesday

THURSDAY

Thursday

FRIDAY

Friday

SATURDAY

Saturday


Updated: 2013.04.25