GlobalVariablesDeleteAll

クライアント端末のグローバル変数を削除します。

int  GlobalVariablesDeleteAll(
  string    prefix_name=NULL,     // プレフィックスで始まる名称を持つ全てのグローバル変数
  datetime   limit_data=0          // この日付より前に変更された全てのグローバル変数
  );

パラメータ

prefix_name=NULL

[in] 削除に使用されるプレフィックス。プレフィックスが、NULLまたは空の文字列に指定されると、データの基準を満たす全ての変数が削除されます。

limit_data=0

[in] 最終変更時刻によってでグローバル変数を選択する時に使用される日付。この関数はこの日付け以前に変更されたグローバル変数を削除します。パラメータがゼロの場合は、最初の基準(プレフィックス)を満たす全ての変数が削除されます。

戻り値

削除された変数の数

注意事項

両方のオプションがゼロに等しい場合(prefix_name= NULLとlimit_data=0)、この関数は端末の全てのグローバル変数を削除します。両方のパラメータが指定されている場合、両方のパラメータに対応するグローバル変数が削除されます。

グローバル変数は、最終アクセス後4週間クライアント端末に保存されてから自動的に削除されます。

 

例:

#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変数
input datetime InpLimitDate= 0;       // リミット日
input string   InpPrefix   = NULL;   // 名前の接頭辞
 
//+------------------------------------------------------------------+
//| スクリプトプログラム開始関数                                              |
//+------------------------------------------------------------------+
void OnStart()
 {
//--- クライアント端末のグローバル変数の総数を取得する
//--- スクリプト設定で選択された削除条件に従って変数を削除し
//--- 削除結果をログに出力する
  int total=GlobalVariablesTotal();
  int deleted=GlobalVariablesDeleteAll(InpPrefix, InpLimitDate);
  PrintFormat("Of %d global variables, %d have been removed. %d remain", total, deleted, total-deleted);
  /*
  結果:
  Of 21 global variables, 21 have been removed. 0 remain
  */
 }