Initial Commit.

This commit is contained in:
ZhijuCen
2026-06-23 21:47:51 +08:00
commit d17f68e979
5201 changed files with 318318 additions and 0 deletions
@@ -0,0 +1,20 @@
# The predefined Variables
For each executable mql5-program a set of predefined variables is supported, which reflect the state of the current price chart by the moment a mql5-program (Expert Advisor, script or custom indicator) is started.
Values of predefined variables are set by the client terminal before a mql5-program is started. Predefined variables are constant and cannot be changed from a mql5-program. As exception, there is a special variable _LastError, which can be reset to 0 by the [ResetLastError](/en/docs/common/resetlasterror) function.
| Variable | Value |
| --- | --- |
| _AppliedTo | The _AppliedTo variable allows finding out the type of data, used for indicator calculation |
| _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 |
| _IsX64 | The _IsX64 variable allows finding out the bit version of the terminal, in which an MQL5 application is running |
Predefined variables cannot be defined in a library. A library uses such variables that are defined in program from which this library is called.
@@ -0,0 +1,74 @@
# int _AppliedTo
The _AppliedTo variable allows finding out the type of data, used for indicator calculation:
| Data type | Meaning | Description of data used for indicator calculation. |
| --- | --- | --- |
| — | 0 | The indicator uses the second OnCalculate() call form - the data for calculation are not specified by a certain buffer or data array |
| Close | 1 | Close prices |
| Open | 2 | Open prices |
| High | 3 | High prices |
| Low | 4 | Low prices |
| Median Price (HL/2) | 5 | Median price = (High+Low)/2 |
| Typical Price (HLC/3) | 6 | Typical price = (High+Low+Close)/3 |
| Weighted Price (HLCC/4) | 7 | Weighted price = (Open+High+Low+Close)/4 |
| Previous Indicator's Data | 8 | Data of the indicator, which was launched on the chart before this indicator |
| First Indicator's Data | 9 | Data of the indicator, which was launched first on the chart |
| Indicator handle | 10+ | Data of the indicator, which was passed to the iCustom() function using the indicator handle. The _AppliedTo value contains the indicator handle |
Example:
```
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
// Getting the type of data used for indicator calculation
   Print("_AppliedTo=",_AppliedTo);
   Print(getIndicatorDataDescription(_AppliedTo));
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Description of data used for indicator calculation               |
//+------------------------------------------------------------------+
string getIndicatorDataDescription(int data_id)
  {
   string descr="";
   switch(data_id)
     {
      case(0):descr="It's first type of OnCalculate() - no data buffer";
         break;
      case(1):descr="Indicator calculates on Close price";
         break;
      case(2):descr="Indicator calculates on Open price";
         break;
      case(3):descr="Indicator calculates on High price";
         break;
      case(4):descr="Indicator calculates on Low price";
         break;
      case(5):descr="Indicator calculates on Median Price (HL/2)";
         break;
      case(6):descr="Indicator calculates on Typical Price (HLC/3)";
         break;
      case(7):descr="Indicator calculates on Weighted Price (HLCC/4)";
         break;
      case(8):descr="Indicator calculates Previous Indicator's data";
         break;
      case(9):descr="Indicator calculates on First Indicator's data";
         break;
      default: descr="Indicator calculates on data of indicator with handle="+string(data_id);
         break;
     }
//---
   return descr;
  }
```
See also
[ENUM_APPLIED_PRICE](/en/docs/constants/indicatorconstants/prices#enum_applied_price_enum)
@@ -0,0 +1,5 @@
# int _Digits
The _Digits variable stores number of digits after a decimal point, which defines the price accuracy of the symbol of the current chart.
You may also use the [Digits()](/en/docs/check/digits) function.
@@ -0,0 +1,5 @@
# double _Point
The _Point variable contains the point size of the current symbol in the quote currency.
You may also use the [Point()](/en/docs/check/point) function.
@@ -0,0 +1,5 @@
# int _LastError
The _LastError variable contains code of the last [error](/en/docs/constants/errorswarnings/errorcodes), that occurred during the mql5-program run. Its value can be reset to zero by [ResetLastError()](/en/docs/common/resetlasterror).
To obtain the code of the last error,  you may also use the [GetLastError()](/en/docs/check/getlasterror) function.
@@ -0,0 +1,9 @@
# ENUM_TIMEFRAMES _Period
The _Period variable contains the value of the timeframe of the current chart.
Also you may use the [Period()](/en/docs/check/period) function.
See also
[PeriodSeconds](/en/docs/common/periodseconds), [Chart timeframes](/en/docs/constants/chartconstants/enum_timeframes), [Date and Time](/en/docs/dateandtime), [Visibility of objects](/en/docs/constants/objectconstants/visible)
@@ -0,0 +1,16 @@
# _RandomSeed
Variable for storing the current state when generating pseudo-random integers. _RandomSeed changes its value when calling [MathRand()](/en/docs/math/mathrand). Use [MathSrand()](/en/docs/math/mathsrand) to set the required initial condition.
x random number received by MathRand() function is calculated in the following way at each call:
```
x=_RandomSeed*214013+2531011;
_RandomSeed=x;
x=(x>>16)&0x7FFF;
```
See also
[MathRand()](/en/docs/math/mathrand), [MathSrand()](/en/docs/math/mathsrand), [Integer types](/en/docs/basis/types/integer)
@@ -0,0 +1,5 @@
# int _StopFlag
The _StopFlag variable contains the mql5 program stop flag equal to 0 during normal operation. When the client terminal tries to stop the program, the variable is set to a value other than zero.
To check the state of the _StopFlag you may also use the [IsStopped()](/en/docs/check/isstopped) function.
@@ -0,0 +1,5 @@
# string _Symbol
The _Symbol variable contains the symbol name of the current chart.
You may also use the [Symbol()](/en/docs/check/symbol) function.
@@ -0,0 +1,5 @@
# int _UninitReason
The _UninitReason variable contains the code of the program [uninitialization reason](/en/docs/constants/namedconstants/uninit).
Usually, this code is obtained by [UninitializeReason()](/en/docs/check/uninitializereason)the function.
@@ -0,0 +1,22 @@
# int _IsX64
The _IsX64 variable allows finding out the bit version of the terminal, in which an MQL5 application is running: _IsX64=0 for the 32-bit terminal and _IsX64!=0 for the 64-bit terminal.
Also, function [TerminalInfoInteger(](/en/docs/check/terminalinfointeger)[TERMINAL_X64](/en/docs/check/terminalinfointeger)[)](/en/docs/check/terminalinfointeger) can be used.
Example:
```
// Checking the terminal, in which the program is running
   Print("_IsX64=",_IsX64);
   if(_IsX64)
      Print("Program ",__FILE__," is running in the 64-bit terminal");
   else
      Print("Program ",__FILE__," is running in the 32-bit terminal");
   Print("TerminalInfoInteger(TERMINAL_X64)=",TerminalInfoInteger(TERMINAL_X64));
```
See also
[MQLInfoInteger](/en/docs/check/mqlinfointeger), [Importing functions (#import)](/en/docs/basis/preprosessor/import)