gyshssl 发表于 2019-8-3 08:57:38

【MT4学习】MQL4语言基础语法--全局变量函数 [



局变量函数bool GlobalVariableCheck( string name)
检查全局变量是否存在
:: 输入参数
name - 全局变量的名称示例:
// checkvariable before use
if(!GlobalVariableCheck("g1"))
GlobalVariableSet("g1",1);

bool GlobalVariableDel(string name)
删除全局变量 :: 输入参数
name - 全局变量的名称示例:
//deleting global variable with name "gvar_1"
GlobalVariableDel("gvar_1");

doubleGlobalVariableGet( string name)
获取全局变量的值 :: 输入参数
name - 全局变量的名称示例:
doublev1=GlobalVariableGet("g1");
//---- check function call result
if(GetLastError()!=0) return(false);
//---- continue processing

doubleGlobalVariableGet( string name)
获取全局变量的值 :: 输入参数
name - 全局变量的名称示例:
doublev1=GlobalVariableGet("g1");
//---- check function call result
if(GetLastError()!=0) return(false);
//---- continue processing

datetimeGlobalVariableSet( string name, double value )
设置全局变量的值 :: 输入参数
name - 全局变量的名称
value - 全局变量的值示例:
//---- tryto set new value
if(GlobalVariableSet("BarsTotal",Bars)==0)
return(false);
//---- continue processing

boolGlobalVariableSetOnCondition( string name, double value, double check_value)
有条件的设置全局变量的值 :: 输入参数
name - 全局变量的名称
value - 全局变量的值
check_value - 检查变量的值示例:
intinit()
{
//---- create global variable
GlobalVariableSet("DATAFILE_SEM",0);
//...
} intstart()
{
//---- try to lock common resource
while(!IsStopped())
{
//---- locking
if(GlobalVariableSetOnCondition("DATAFILE_SEM",1,0)==true) break;
//---- may be variable deleted?
if(GetLastError()==ERR_GLOBAL_VARIABLE_NOT_FOUND) return(0);
//---- sleeping
Sleep(500);
}
//---- resource locked
// ... do some work
//---- unlock resource
GlobalVariableSet("DATAFILE_SEM",0);
}

voidGlobalVariablesDeleteAll( )
删除所有全局变量
示例:GlobalVariablesDeleteAll();


添加客服微信,获取整套MQL4学习资料。




页: [1]
查看完整版本: 【MT4学习】MQL4语言基础语法--全局变量函数 [