GlobalVariableSet

글로벌 변수의 새 값을 설정. 변수가 없으면 시스템에서 새 글로벌 변수를 생성합니다.

datetime  GlobalVariableSet(
   string  name,      // 글로벌 변수 이름
   double  value      // 설정할 값
   );

매개변수

이름

[in]  글로벌 변수 이름.

[in]  새 숫자 값.

값 반환

성공하면 함수는 마지막 수정 시간을, 그렇지 않으면 0을 반환합니다. 오류에 대한 자세한 내용은, GetLastError()를 호출하십시오.

주의

글로벌 변수 이름은 63자를 초과할 수 없습니다. 글로벌 변수는 마지막 사용 후 4주 동안 클라이언트 터미널에 존재하면 자동으로 삭제됩니다.

 

예:

#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#define   GV_NAME    "TestGlobalVariableSet"
#define   GV_VALUE   1.23456
 
//+------------------------------------------------------------------+
//| 스크립트 프로그램 시작 함수                                         |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- 새로운 GV_VALUE 값을 클라이언트 터미널의 전역 변수인 GV_NAME으로 설정합니다.
//--- 변수가 아직 존재하지 않으면 생성됩니다.
   if(GlobalVariableSet(GV_NAMEGV_VALUE)==0)
     {
         Print("GlobalVariableSet() failed. Error "GetLastError());
      return;
     }
//--- 결과를 확인하고 저널에 출력합니다.
   double value=0;
   if(GlobalVariableGet(GV_NAMEvalue))
     {
      PrintFormat("The global variable of the client terminal named \"%s\" is set to %.5f"GV_NAMEvalue);
     }
   /*
   결과:
   The global variable of the client terminal named "TestGlobalVariableSet" is set to 1.23456
   */
  }