GlobalVariablesDeleteAll

删除客户端的全局变量。

int  GlobalVariablesDeleteAll(
   string     prefix_name=NULL,     // 所有带有前缀的全局变量
   datetime   limit_data=0          // 所有该日期前已更改的全局变量
   );

参量

prefix_name=NULL

[in]将被删除的全局变量的命名前缀。如果指定前缀是NULL或者空字符串,所有满足数据标准的变量都会被删除。

limit_data=0

[in] 通过上次修正时间来选择全局变量,函数删除在此日期之前改变的全局变量,如果参量是0,所有满足第一标准(前缀)的变量都会被删除。

返回值

删除变量数量。

Note

如果每个选项等于0 (prefix_name = NULL and limit_data = 0), 函数删除终端所有的全局变量。如果所有的参量都是制定的,删除与该参量相关的全局变量。

全局变量在客户端保存自最后使用的四周,然后自动删除。

 

示例:

#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#property script_show_inputs
 
#property description   "The script deletes global variables of the client terminal."
#property description   "Limit date: Variables before the specified date are deleted."
#property description   "If is zero, then variables that match the Name prefix criterion are deleted."
#property description   "Name prefix: Prefix of the variable name. If not specified, then variables are deleted based on the Limit date criterion."
#property description   "If all input parameters are zero, then all global variables are deleted."
#property description   "If both parameters are specified, then global variables corresponding to each of the specified parameters are deleted."
 
//--- 输入变量
input datetime InpLimitDate=  0;       // 限制日期
input string   InpPrefix   =  NULL;    // 名称前缀
 
//+------------------------------------------------------------------+
//| 脚本程序起始函数                                                   |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- 获取客户端的全局变量总数,
//--- 根据脚本设置中选择的删除标准删除变量,并且
//--- 在日志中打印删除结果
   int total=GlobalVariablesTotal();
   int deleted=GlobalVariablesDeleteAll(InpPrefixInpLimitDate);
   PrintFormat("Of %d global variables, %d have been removed. %d remain"totaldeletedtotal-deleted);
   /*
  结果:
   Of 21 global variables21 have been removed0 remain
   */
  }