Predefined Macro Substitutions
Predefined Macro Substitutions
预定义的宏替换
为了简化调试过程并获取有关mql4程序运行的信息,有一些特殊的宏常量,这些常量在编译时设置。使用这些常量最简单的方法是通过Print()函数输出其值,如示例所示。
| 常量 | 描述 |
|---|---|
| __DATE__ | 文件编译日期,不包括时间(小时、分钟和秒均为0) |
| __DATETIME__ | 文件编译的日期和时间 |
| __LINE__ | 源代码中包含宏的行号 |
| __FILE__ | 当前正在编译的文件的名称 |
| __PATH__ | 当前正在编译的文件的绝对路径 |
| __FUNCTION__ | 宏所在函数的名称 |
| __FUNCSIG__ | 宏所在函数签名。记录函数的完整描述有助于识别重载函数 |
| __MQLBUILD__, __MQL4BUILD__ | 编译器构建编号 |
示例:
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- an example of information output at Expert Advisor initialization
Print(" __FUNCTION__ = ",__FUNCTION__," __LINE__ = ",__LINE__);
//--- set the interval between the timer events
EventSetTimer(5);
//---
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- an example of information output at Expert Advisor deinitialization
Print(" __FUNCTION__ = ",__FUNCTION__," __LINE__ = ",__LINE__);
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- information output at tick receipt
Print(" __MQLBUILD__ = ",__MQLBUILD__," __FILE__ = ",__FILE__);
Print(" __FUNCTION__ = ",__FUNCTION__," __LINE__ = ",__LINE__);
test1(__FUNCTION__);
test2();
//---
}
//+------------------------------------------------------------------+
//| test1 |
//+------------------------------------------------------------------+
void test1(string par)
{
//--- information output inside the function
Print(" __FUNCTION__ = ",__FUNCTION__," __LINE__ = ",__LINE__," par = ",par);
}
//+------------------------------------------------------------------+
//| test2 |
//+------------------------------------------------------------------+
void test2()
{
//--- information output inside the function
Print(" __FUNCTION__ = ",__FUNCTION__," __LINE__ = ",__LINE__);
}
//+------------------------------------------------------------------+
//| OnTimer event handler |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
Print(" __FUNCTION__ = ",__FUNCTION__," __LINE__ = ",__LINE__);
test1(__FUNCTION__);
}
//+------------------------------------------------------------------+
最后更新于