Global Variables of the Terminal expiry

 
Is there a way to make Global Variables of the Terminal that don't expire?
 
ycomp: Is there a way to make Global Variables of the Terminal that don't expire?

No! Instead, just access them regularly! Optionally create your own file structure, in the common folder for example, for storing data.

 

is there a way to edit the config of the terminal or something like that so that all global variables have a longer expiry than 4 weeks?

 
ycomp #:is there a way to edit the config of the terminal or something like that so that all global variables have a longer expiry than 4 weeks?

I have already answered, no! Just access the variables (a simple "get") and they will be automatically refreshed.

If you really want to, write a MQL5 Service program to cycle over all the variables and refresh them regularly.

 
ycomp: Is there a way to make Global Variables of the Terminal that don't expire?

Why do you think you need that?
     How To Ask Questions The Smart Way. (2004)
          The XY Problem
          Be precise and informative about your problem

 

well it would have been nice to use global variables because then I wouldn't have to deal with potential errors from trying to read files instead of using global variables. 

I need to keep track of an important number that is persistent. Well a bunch of them but only one of these per EA. 

I understand about checking to keep them alive, however this only works if you check once in 4 weeks. Which will happen much of the time but cannot be guaranteed.

Service program is a good idea but not really that applicable for my situation, because I might switch accounts and come back to an older account later (after more than 4 weeks) (ok I guess that doesn't matter but I mean the a terminal might not be running for more than a month in some cases)

So I guess I will need to store it in files and then deal with error handling for that. It is a crucial number for managing of my trading operations with the EA.

honestly if I was coding just MQL4 I would just use extern inputs, but for some reason that got removed in MQL5.
 
ycomp #: I was coding just MQL4 I would just use extern inputs, but for some reason that got removed in MQL5.

It was not removed. It was renamed in both MQL4+ and MQL5 to the word "input" instead of "extern".

On MQL5, "extern" is for referencing extern variables, useful for compiled libraries.

 

ok I'm a bit confused now. Can I modify the value of input in mql5? like you could in MQL4 when it was extern? do I need to use some special modifier for that to work?

I did a lot of workaround code for this which I'm not very happy with because I couldn't figure out how to assign a value programmatically in MQL5 to an input like you could in MQL4 with extern.

 
ycomp #:

ok I'm a bit confused now. Can I modify the value of input in mql5? like you could in MQL4 when it was extern?

I did a lot of workaround code for this which I'm not very happy with because I couldn't figure out how to assign a value programmatically in MQL5 to an input like you could in MQL4 with extern.

No you can't, they are constants. Just assign the input value to a standard variable if you need to change it.

But how is that related to your Global Variables topic ?

 
ycomp #: ok I'm a bit confused now. Can I modify the value of input in mql5? like you could in MQL4 when it was extern? I did a lot of workaround code for this which I'm not very happy with because I couldn't figure out how to assign a value programmatically in MQL5 to an input like you could in MQL4 with extern.

Just assign the "input" to a globally scoped variable during OnInit(), and then you can use and modify that variable as much as you wish.

// Untested, uncompiled example code

input double i_dbRangeFactor = 1.0; // Range factor

double g_dbRangeFactor; // Range factor

int OnInit( void ) {
   g_dbRangeFactor = i_dbRangeFactor < 1 ? 1 : i_dbRangeFactor;
};

void OnTick( void ) {
   // other code

   double dbBands = dbHighLow * g_dbRangeFactor;

   // other code
};
 
Alain Verleyen #:

No you can't, they are constants. Just assign the input value to a standard variable if you need to change it.

But how is that related to your Global Variables topic ?

I was just saying that in MQL4 I would have just used extern to save the value persistently but because I'm developing code that works for both MQL4/5, I can't do this.

So I was looking to use global variables, but they expire. So I wrote using them now but in the future I will implement a more robust solution using file storage I guess.

ah I guess I wasn't thinking too much there as the I wouldn't want the user messing with the variable.

Reason: