#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#define GV_NAME "TestGlobalVariableTemp"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
double value=0; // aquí recibiremos los valores de la variable global
//--- si aún no existe una variable global temporal de terminal de cliente, entonces:
//--- 1. o bien el programa aún no se ha iniciado,
//--- 2. o bien ha habido un reinicio del terminal con el programa ejecutándose
if(!GlobalVariableCheck(GV_NAME))
{
//--- creamos una nueva variable global temporal para el terminal de cliente
if(!GlobalVariableTemp(GV_NAME))
{
Print("GlobalVariableTemp() failed. Error ", GetLastError());
return;
}
//--- establecemos la fecha y hora actuales en la variable global
if(!GlobalVariableSet(GV_NAME,(double)TimeCurrent()))
{
Print("GlobalVariableSet() failed. Error ", GetLastError());
return;
}
//--- obtenemos el valor de una variable global temporal y enviamos al registro la hora del primer inicio del programa o reinicio del terminal.
if(!GlobalVariableGet(GV_NAME,value))
{
Print("GlobalVariableGet() failed. Error ", GetLastError());
return;
}
Print("First start or starting the program after rebooting the terminal at ", TimeToString((datetime)value,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
}
//--- si ya se ha creado la variable global temporal de terminal de cliente, entonces se tratará de un reinicio del programa.
else
{
//--- establecemos la fecha y hora actuales en la variable global
if(!GlobalVariableSet(GV_NAME,(double)TimeCurrent()))
{
Print("GlobalVariableSet() failed. Error ", GetLastError());
return;
}
//--- obtenemos el valor de la variable global temporal y mostramos la hora de reinicio del programa en el registro
if(!GlobalVariableGet(GV_NAME,value))
{
Print("GlobalVariableGet() failed. Error ", GetLastError());
return;
}
Print("Restarting the program at ", TimeToString((datetime)value, TIME_DATE|TIME_MINUTES|TIME_SECONDS));
}
/*
resultado en el primer inicio, o después de reiniciar el terminal:
First start or starting the program after rebooting the terminal at 2024.11.29 15:03:18
resultado de varios reinicios consecutivos del programa:
Restarting the program at 2024.11.29 15:03:25
Restarting the program at 2024.11.29 15:03:33
Restarting the program at 2024.11.29 15:03:45
*/
}
|