#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; // riceveremo qui i valori della variabile globale
//--- se non esiste ancora una variabile globale temporanea del terminale client, allora:
//--- 1. o il programma non è ancora stato lanciato,
//--- 2. oppure si è verificato un riavvio del terminale con il programma in esecuzione
if(!GlobalVariableCheck(GV_NAME))
{
//--- creare una nuova variabile globale temporanea per il terminale client
if(!GlobalVariableTemp(GV_NAME))
{
Print("GlobalVariableTemp() failed. Error ", GetLastError());
return;
}
//--- impostare la data e l'ora correnti nella variabile globale
if(!GlobalVariableSet(GV_NAME,(double)TimeCurrent()))
{
Print("GlobalVariableSet() failed. Error ", GetLastError());
return;
}
//--- ottenere il valore della variabile globale temporanea e visualizzare nel journal l'ora del primo avvio del programma o del riavvio del terminale
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));
}
//--- se la variabile globale temporanea del terminale client è già stata creata, allora si tratta di un riavvio del programma
else
{
//--- impostare la data e l'ora correnti nella variabile globale
if(!GlobalVariableSet(GV_NAME,(double)TimeCurrent()))
{
Print("GlobalVariableSet() failed. Error ", GetLastError());
return;
}
//--- ottenere il valore della variabile globale temporanea e stampare l'ora di riavvio del programma nel 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));
}
/*
risultato durante il primo avvio, o dopo il riavvio del terminale:
First start or starting the program after rebooting the terminal at 2024.11.29 15:03:18
il risultato di diversi riavvii consecutivi del programma:
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
*/
}
|