GlobalVariableTime

글로벌 변수에 마지막으로 액세스한 시간을 반환.

datetime  GlobalVariableTime(
   string  name      // 이름
   );

매개변수

이름

[in]  글로별 변수 이름.

값 반환

함수는 지정된 글로벌 변수에 마지막으로 액세스한 시간을 반환합니다. GlobalVariableGet()GlobalVariableCheck() 기능을 사용하여 변수에 주소를 지정하면 마지막 액세스 시간도 수정됩니다. 오류에 대한 자세한 내용을 얻기 위해 GetLastError() 기능을 호출하십시오.

주의

글로벌 변수는 마지막 호출 후 4주 동안 클라이언트 너미널에 존재합니다. 그 이후 자동으로 삭제됩니다.

 

예:

#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#define   GV_NAME    "TestGlobalVariableTime"
#define   GV_TOTAL   5
 
//+------------------------------------------------------------------+
//| 스크립트 프로그램 시작 함수                                         |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- 테스트를 위해 생성된 GV_NAME 접두사가 있는 클라이언트 터미널의 전역 변수를 삭제합니다.
   GlobalVariablesDeleteAll(GV_NAME);
   
//--- GV_TOTAL 양만큼 클라이언트 터미널 전역 변수를 생성합니다.
//--- GV_NAME 접두사와 각 항목 생성 사이의 5초 간격을 포함합니다
   for(int i=0i<GV_TOTALi++)
     {
      string name=GV_NAME+"_"+(string)i;
      ulong value=GetMicrosecondCount();
      ResetLastError();
      datetime time=GlobalVariableSet(name, (double)value);
      if(time==0)
        {
         Print("GlobalVariableSet() failed. Error "GetLastError());
         continue;
        }
      Sleep(5000);
      PrintFormat("GlobalVariableSet(%s, %.0f). Create time: %s"namevalueTimeToString(time,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
     }
     
//--- 몇 초간 기다린 후 GV_NAME 접두사가 있는 터미널 전역 변수의 생성 시간을 저널에 출력합니다.
   Sleep(2000);
   Print(""); 
   GlobalVariableTimePrint("Creation time");
   
//--- 몇 초 더 기다린 후 GV_NAME 접두사가 있는 터미널 전역 변수에 대한 마지막 액세스 시간을 저널에 출력합니다.
//--- 각 변수에 대한 마지막 접근 시간이 변수 생성 시간과 동일함을 알 수 있습니다.
    Sleep(2000);
   Print(""); 
   GlobalVariableTimePrint("Last access time");
 
//--- 이제 생성된 각 변수의 값을 요청합니다.
   Print(""); 
   int total=GlobalVariablesTotal();
   for(int i=0i<totali++)
     {
      string name=GlobalVariableName(i);
      if(GetLastError()!=0)
        {
         PrintFormat("Error %d occurred while getting global variable name at index %d"GetLastError(), i);
      ResetLastError();
         continue;
        }
      if(StringFind(nameGV_NAME)==WRONG_VALUE)
         continue;
         
      double value=GlobalVariableGet(name);
      if(GetLastError()!=0)
        {
         PrintFormat("Error %d occurred while getting global variable value at index %d"GetLastError(), i);
      ResetLastError();
         continue;
        }
      PrintFormat("Value of global variable named \"%s\": %.0f"namevalue);
     }
   
//--- 몇 초 더 기다린 후 GV_NAME 접두사가 있는 터미널 전역 변수에 대한 마지막 액세스 시간을 저널에 출력합니다.
//--- 각 변수에 대한 마지막 접근 시간이 해당 값을 요청하는 시간과 동일함을 알 수 있습니다.
    Sleep(2000);
   Print(""); 
   GlobalVariableTimePrint("After getting value, the last access time");
 
//--- 클라이언트 터미널의 테스트를 위해 생성된 GV_NAME 접두사가 있는 모든 전역 변수를 삭제합니다.
   GlobalVariablesDeleteAll(GV_NAME);
   /*
   결과:
   GlobalVariableSet(TestGlobalVariableTime_03987). Create time2024.11.28 22:00:39
   GlobalVariableSet(TestGlobalVariableTime_15012302). Create time2024.11.28 22:00:44
   GlobalVariableSet(TestGlobalVariableTime_210034365). Create time2024.11.28 22:00:49
   GlobalVariableSet(TestGlobalVariableTime_315045008). Create time2024.11.28 22:00:54
   GlobalVariableSet(TestGlobalVariableTime_420060340). Create time2024.11.28 22:00:59
   
   Creation time of global variable named "TestGlobalVariableTime_0"2024.11.28 22:00:39
   Creation time of global variable named "TestGlobalVariableTime_1"2024.11.28 22:00:44
   Creation time of global variable named "TestGlobalVariableTime_2"2024.11.28 22:00:49
   Creation time of global variable named "TestGlobalVariableTime_3"2024.11.28 22:00:54
   Creation time of global variable named "TestGlobalVariableTime_4"2024.11.28 22:00:59
   
   Last access time of global variable named "TestGlobalVariableTime_0"2024.11.28 22:00:39
   Last access time of global variable named "TestGlobalVariableTime_1"2024.11.28 22:00:44
   Last access time of global variable named "TestGlobalVariableTime_2"2024.11.28 22:00:49
   Last access time of global variable named "TestGlobalVariableTime_3"2024.11.28 22:00:54
   Last access time of global variable named "TestGlobalVariableTime_4"2024.11.28 22:00:59
   
   Value of global variable named "TestGlobalVariableTime_0"3987
   Value of global variable named "TestGlobalVariableTime_1"5012302
   Value of global variable named "TestGlobalVariableTime_2"10034365
   Value of global variable named "TestGlobalVariableTime_3"15045008
   Value of global variable named "TestGlobalVariableTime_4"20060340
   
   After getting valuethe last access time of global variable named "TestGlobalVariableTime_0"2024.11.28 22:01:08
   After getting valuethe last access time of global variable named "TestGlobalVariableTime_1"2024.11.28 22:01:08
   After getting valuethe last access time of global variable named "TestGlobalVariableTime_2"2024.11.28 22:01:08
   After getting valuethe last access time of global variable named "TestGlobalVariableTime_3"2024.11.28 22:01:08
   After getting valuethe last access time of global variable named "TestGlobalVariableTime_4"2024.11.28 22:01:08
   */
  }
//+------------------------------------------------------------------+
//| 마지막 접근 시간을 도구 모음에 출력합니다.                            |
//| 클라이언트 터미널의 전역 변수에                                      |
//+------------------------------------------------------------------+
void GlobalVariableTimePrint(const string reason)
  {
   int total=GlobalVariablesTotal();
   for(int i=0i<totali++)
     {
      string name=GlobalVariableName(i);
      if(GetLastError()!=0)
        {
         PrintFormat("Error %d occurred while getting global variable name at index %d"GetLastError(), i);
      ResetLastError();
         continue;
        }
      datetime time=GlobalVariableTime(name);
      if(GetLastError()!=0)
        {
         PrintFormat("Error %d occurred while getting global variable time at index %d"GetLastError(), i);
      ResetLastError();
         continue;
        }
      PrintFormat("%s of global variable named \"%s\": %s"reasonnameTimeToString(time,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
     }
  }

추가 참조

GlobalVariableCheck()