#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; // nous récupérerons les valeurs de la variable globale ici
//--- s'il n'y a pas encore de variable globale temporaire du terminal client, alors :
//--- 1. soit le programme n'est pas encore lancé,
//--- 2. ou il y a eu un redémarrage du terminal avec le programme en cours d'exécution
if(!GlobalVariableCheck(GV_NAME))
{
//--- crée une nouvelle variable globale temporaire pour le terminal client
if(!GlobalVariableTemp(GV_NAME))
{
Print("GlobalVariableTemp() failed. Error ", GetLastError());
return;
}
//--- affecte la date et l'heure actuelles à la variable globale
if(!GlobalVariableSet(GV_NAME,(double)TimeCurrent()))
{
Print("GlobalVariableSet() failed. Error ", GetLastError());
return;
}
//--- récupére la valeur de la variable globale temporaire et affiche dans le journal l'heure du premier lancement du programme ou du redémarrage du 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 la variable globale temporaire du terminal client a déjà été créée, alors il s'agit d'un redémarrage du programme
else
{
//--- affecte la date et l'heure actuelles à la variable globale
if(!GlobalVariableSet(GV_NAME,(double)TimeCurrent()))
{
Print("GlobalVariableSet() failed. Error ", GetLastError());
return;
}
//--- récupère la valeur de la variable globale temporaire et imprime l'heure de redémarrage du programme dans le journal
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));
}
/*
résultat lors du premier lancement, ou après redémarrage du terminal :
First start or starting the program after rebooting the terminal at 2024.11.29 15:03:18
le résultat de plusieurs redémarrages consécutifs du programme :
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
*/
}
|