How can I clear my MT4 from global variables automatically everytime MT4 starts or every hour?

 

Hello,

How can I clear my MT4 from global variables automatically everytime MT4 starts or every hour?

thanks

Ricardo.

 
You can't. Terminal variables are kept for a month after last use. If you want to clear them, you must do it.
 

If you use GlobalVariableTemp() they will be automatically deleted when the terminal closes.

 
honest_knave:

If you use GlobalVariableTemp() they will be automatically deleted when the terminal closes.

how can i do it?

how can i run this script everytime MT4 starts or closes?

Remember my robot is already running. Thanks for your support.


i found this script too.

//--------------------------------------------------------------------
// deleteall.mq4
// The program is intended to be used as an example in MQL4 Tutorial.
//--------------------------------------------------------------------
int start()                             // Special start() function
  {
   GlobalVariablesDeleteAll();          // Deleting of all GVs
   PlaySound("W2.wav");                 // Sound
   return;                              // Exit
  }
//--------------------------------------------------------------------
 

This code can be added to your EA to delete all your global variables every hour, and whenever the EA gets initialized (i.e. when the terminal starts).

#property strict
   
int OnInit()
  {
   // your normal code
   EventSetTimer(1);
   OnTimer();       
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
   // your normal code
   EventKillTimer();
  }

void OnTick()
  {
   // your normal code
  }

void OnTimer()
  {
   static int LastHour = -1;
   int ThisHour=Hour();
   if(LastHour!=ThisHour)
     {
      GlobalVariablesDeleteAll();     
      LastHour=ThisHour;
     }
  }
 
honest_knave:

This code can be added to your EA to delete all your global variables every hour, and whenever the EA gets initialized (i.e. when the terminal starts).

 

thank you for your answer but  I don't have access of the EA. The EA is not mine.

Is there another way? something i can add when MT4 starts and make loop with GlobalVariablesDeleteAll

Thanks for your help
 
Ricardo2016:

thank you for your answer but  I don't have access of the EA. The EA is not mine.

Is there another way? something i can add when MT4 starts and make loop with GlobalVariablesDeleteAll

Thanks for your help
Then it may not be a good idea to delete the GVs. The EA may not work properly if they are deleted
 

You can write your own indicator or EA (that code above is a complete EA if required) that does the above. Just make sure it is applied to a chart in your terminal and it will delete all GVs.

But please heed GumRai's warning. You could well break something in your other EAs and/or indicators.

 
GumRai:
Then it may not be a good idea to delete the GVs. The EA may not work properly if they are deleted
thank you.
 
honest_knave:

You can write your own indicator or EA (that code above is a complete EA if required) that does the above. Just make sure it is applied to a chart in your terminal and it will delete all GVs.

But please heed GumRai's warning. You could well break something in your other EAs and/or indicators.

Ok. Thank you!
Reason: