You are on page 1of 3

MQL4 has a number of predefined variables that already exists and be used in an expert

advisor, indicator, or script. When using these variables, remember the following points:
• They are already declared – no need for redeclaring them on the source code
• The names for these variables are reserved – you may not define new variables that
has the same name for the predefined variables.
• The values contained for these variables are for the chart where the program (expert
advisor, indicator, or script) is loaded. The values may change once you switch to a
different instrument or currency pair.

A complete list of these variables are listed below:

Variable Description
_Digits Number of decimal places for price on chart
_Point Size of 1 point on current quote currency
_LastError Last error encountered
_Period Current period (timeframe) on chart
_RandomSeed Current seed for the random numer generator
_StopFlag Program stop flag
_Symbol Name of symbol for current chart
_UninitReason Uninitialization reason
Ask Ask price
Bars Number of bars on chart
Bid Bid price
Close Series array for close prices on chart
Digits No. of decimal places for price on current
chart
High Series array for high prices on chart
Low Series array for low prices on chart
Open Series array for open prices on chart
Point Size of 1 point on current quote currency
Time Series array for open times on chart
Volume Series array for tick volumes on chart
It would be helpful if you can familiarize yourself with all of the predefined variables at this
point. But for now, knowing the following predefined variables shall be enough:

Variable Description
_Symbol Name of symbol for current chart
_Digits Number of decimal places for price on chart
_Point Size of 1 point on current quote currency
_Period Current period (timeframe) on chart
Ask Ask price
Bid Bid price
Digits No. of decimal places for price on current
chart
Point Size of 1 point on current quote currency

Symbol
_Symbol gives the name of the instrument or currency pair where an instance of an EA, script,
or indicator is loaded on. For example, consider loading an EA on a EURUSD chart with the
following OnTick() code:

void OnTick()
{
Print("The EA is loaded on "+_Symbol+".");
ExpertRemove();
}

Prints:
The EA is loaded on EURUSD.

Alternatively, the function equivalent of _Symbol, which is Symbol(), can also be used, with the
same result:
void OnTick()
{
Print("The EA is loaded on "+Symbol()+".");
ExpertRemove();
}

Prints:
The EA is loaded on EURUSD.

Digits
_Digits gives the number of digits of the price on the current chart. Building from the previous
example:

void OnTick()
{
Print("The EA is loaded on "+_Symbol+". Its price has "+_Digits+" digits after the decimal
point.");
ExpertRemove();
}

Prints:
The EA is loaded on EURUSD. Its price has 5 digits after the decimal point.
This is assuming that the broker being used offers fractional pip pricing. If it does not, then the
digits reported will be 4.

Alternatively, Digits can be used instead of _Digits.

Point
_Point gives the value of 1 point in the price. Building from the previous example:
void OnTick()
{
Print("The EA is loaded on "+_Symbol+". Its price has "+_Digits+" digits after the decimal
point.");
Print("Thus, for this instrument, 1 point = "+Point+".");
ExpertRemove();
}

Prints:
The EA is loaded on EURUSD. Its price has 5 digits after the decimal point.
Thus, for this instrument, 1 point = 0.00001.

Alternatively, Point can be used instead of _Point.

Period
_Period returns the current timeframe of the chart. Building from the previous example:
void OnTick()
{
Print("The EA is loaded on "+_Symbol+" "+_Period". Its price has "+_Digits+" digits after
the decimal point.");
Print("Thus, for this instrument, 1 point = "+Point+".");
ExpertRemove();
}

Prints:
The EA is loaded on EURUSD H1. Its price has 5 digits after the decimal point.
Thus, for this instrument, 1 point = 0.00001.

This is assuming that the EA is loaded on an EURUSD H1 chart.

Bid and Ask


Bid returns the value of the bid price, while Ask returns the value of the asking price. Building
from the previous example:

void OnTick()
{
Print("The EA is loaded on "+_Symbol+" "+_Period". Its price has "+_Digits+" digits after
the decimal point.");
Print("Thus, for this instrument, 1 point = "+Point+".");
Print("bid/ask: "+Bid+"/"+Ask+".");
ExpertRemove();
}

Prints:
The EA is loaded on EURUSD H1. Its price has 5 digits after the decimal point.
Thus, for this instrument, 1 point = 0.00001.
bid/ask: 1.08940/1.08930.

You might also like