跳至内容

Predefined Variables

预定义变量

每个可执行的 mql4-程序都支持一组预定义变量,这些变量反映了 mql4-程序(专家顾问、脚本或自定义指标)启动时的当前价格图表状态。

预定义变量的值由客户端终端在 mql4-程序启动前设置。预定义变量是常量,无法在 mql4-程序中更改。例外情况是一个特殊的变量 _LastError,可以通过 ResetLastError 函数将其重置为 0。

变量
_Digits小数位数
_Point当前符号点在报价货币中的大小
_LastError最后的错误代码
_Period当前图表的时间框架
_RandomSeed伪随机整数生成器的当前状态
_StopFlag程序停止标志
_Symbol当前图表的符号名称
_UninitReason初始化原因代码
Ask当前符号的最新已知卖方价格(卖价)
Bars当前图表中的条形数
Bid当前符号的最新已知买方价格(买价)
Close包含当前图表每个条形收盘价的数据数组
Digits当前符号价格的小数位数
High包含当前图表每个条形最高价格的数据数组
Low包含当前图表每个条形最低价格的数据数组
Open包含当前图表每个条形开盘价的数据数组
Point当前符号点在报价货币中的值
Time包含当前图表每个条形开盘时间的数据数组
Volume包含当前图表每个条形成交量的数据数组

预定义变量不能在库中定义。库使用的变量是调用该库的程序中定义的变量。

示例:

//+------------------------------------------------------------------+
//| 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);
  }
最后更新于