Skip to content

Predefined Variables

The predefined Variables

For each executable mql4-program a set of predefined variables is supported, which reflect the state of the current price chart by the moment a mql4-program (Expert Advisor, script or custom indicator) is started.

Values of predefined variables are set by the client terminal before a mql4-program is started. Predefined variables are constant and cannot be changed from a mql4-program. As exception, there is a special variable _LastError, which can be reset to 0 by the ResetLastError function.

VariableValue
_DigitsNumber of decimal places
_PointSize of the current symbol point in the quote currency
_LastErrorThe last error code
_PeriodTimeframe of the current chart
_RandomSeedCurrent status of the generator of pseudo-random integers
_StopFlagProgram stop flag
_SymbolSymbol name of the current chart
_UninitReasonUninitialization reason code
AskThe latest known seller’s price (ask price) of the current symbol
BarsNumber of bars in the current chart
BidThe latest known buyer’s price (offer price, bid price) of the current symbol
CloseSeries array that contains close prices for each bar of the current chart
DigitsNumber of digits after decimal point for the current symbol prices
HighSeries array that contains the highest prices of each bar of the current chart
LowSeries array that contains the lowest prices of each bar of the current chart
OpenSeries array that contains open prices of each bar of the current chart
PointThe current symbol point value in the quote currency
TimeSeries array that contains open time of each bar of the current chart
VolumeSeries array that contains tick volumes of each bar of the current chart

Predefined variables cannot be defined in a library. A library uses such variables that are defined in program from which this library is called.

Example:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   Print("Symbol name of the current chart=",_Symbol);
   Print("Timeframe of the current chart=",_Period);
   Print("The latest known seller's price (ask price) for the current symbol=",Ask);
   Print("The latest known buyer's price (bid price) of the current symbol=",Bid);
   Print("Number of decimal places=",Digits);
   Print("Number of decimal places=",_Digits);
   Print("Size of the current symbol point in the quote currency=",_Point);
   Print("Size of the current symbol point in the quote currency=",Point);
   Print("Number of bars in the current chart=",Bars);
   Print("Open price of the current bar of the current chart=",Open[0]);
   Print("Close price of the current bar of the current chart=",Close[0]);
   Print("High price of the current bar of the current chart=",High[0]);
   Print("Low price of the current bar of the current chart=",Low[0]);
   Print("Time of the current bar of the current chart=",Time[0]);
   Print("Tick volume of the current bar of the current chart=",Volume[0]);
   Print("Last error code=",_LastError);
   Print("Random seed=",_RandomSeed);
   Print("Stop flag=",_StopFlag);
   Print("Uninitialization reason code=",_UninitReason);
  }
Last updated on