Download MetaTrader 5
To add comments, please log in or register
Make screenshots in MetaTrader and manage them in the gallery!
Ricardo Carvalho
26
Ricardo Carvalho 2016.01.28 16:55 

Hello,

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

thanks

Ricardo.

whroeder1
13602
whroeder1 2016.01.29 00:45  
You can't. Terminal variables are kept for a month after last use. If you want to clear them, you must do it.
honest_knave
954
honest_knave 2016.01.29 13:49  

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

Ricardo Carvalho
26
Ricardo Carvalho 2016.01.30 01:07  
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
  }
//--------------------------------------------------------------------
honest_knave
954
honest_knave 2016.01.31 07:57  

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;
     }
  }
Ricardo Carvalho
26
Ricardo Carvalho 2016.02.02 02:06  
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
Keith Watford
Moderator
7892
Keith Watford 2016.02.02 02:41  
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
honest_knave
954
honest_knave 2016.02.02 07:28  

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.

Ricardo Carvalho
26
Ricardo Carvalho 2016.02.02 13:11  
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.
Ricardo Carvalho
26
Ricardo Carvalho 2016.02.02 13:12  
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!
/
To add comments, please log in or register