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.
| Variable | Value |
|---|---|
| _Digits | Number of decimal places |
| _Point | Size of the current symbol point in the quote currency |
| _LastError | The last error code |
| _Period | Timeframe of the current chart |
| _RandomSeed | Current status of the generator of pseudo-random integers |
| _StopFlag | Program stop flag |
| _Symbol | Symbol name of the current chart |
| _UninitReason | Uninitialization reason code |
| Ask | The latest known seller’s price (ask price) of the current symbol |
| Bars | Number of bars in the current chart |
| Bid | The latest known buyer’s price (offer price, bid price) of the current symbol |
| Close | Series array that contains close prices for each bar of the current chart |
| Digits | Number of digits after decimal point for the current symbol prices |
| High | Series array that contains the highest prices of each bar of the current chart |
| Low | Series array that contains the lowest prices of each bar of the current chart |
| Open | Series array that contains open prices of each bar of the current chart |
| Point | The current symbol point value in the quote currency |
| Time | Series array that contains open time of each bar of the current chart |
| Volume | Series 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