question on global variables lifespan and security/persistentcy

 

Do you know if the client terminals global variables are safe?

I mean safe in context of reasonable warranty that even if terminal crashes or whatever, on restart the previous GVAR state will be reinstated.

Asking because it seems to me that only unique data available to a generic EA [which could be running on many charts] is the Symbol() and Period() of the chart it finds itself applied to. Assuming you never allow the generic EA to run on more than one of: same sym,period chart setup, it could follow that the sym,period data is enough to construct GVAR name which allows the EA to 'reinstate' it's previous run state - am thinking disk file(s) name(s) that keep the EA's current processing state and possibly logs for trading and general processing messages (eg, alternatives to Print() )

It seems that above depends on terminal GVAR persistentcy - regardless of what happens to the terminal. For instance, when a GVAR is created and given a value plus future updates to this GVAR, does terminal flush this GVAR state to safe location ie, disk file? and... do this on immediate or queued schedule?

A generic EA that is fully used as auto trading robot surely means periods of unattended running [and trading!] during which time the terminal may experience runtime issues causing EA to be restarted [as if for the first time] and init() is called. I would expect the EA to realise 'who it is' and that it is being restarted and that it may have outstanding pending and/or open orders with broker. This requires EA to reinstate previous runtime processing environment, yes? and to do this the EA needs at least one datum to allow it to reinstate previous runtime enviornment, yes?

Sure would appreciate reading your views and ideas :-)

 
See https://docs.mql4.com/globals

A group of functions intended for working with global variables.

Global variables of the client terminal should not be mixed up with variables declared in the global scope of the MQL4 program.

Global variables are kept in the client terminal within 4 weeks since the last access, then they will be deleted automatically. An access to a global variable is not only setting of a new value, but reading of the global variable value, as well.

Global variables of the client terminal are accessible simultaneously from all MQL4 programs launched in the client terminal.
 

Thank you, Yes, I understand about global scoped variables in EA execution units and global varables in CT execution enviornments and how to employ them [CT gvars], as resource access semaphores or as sinks for variable data storage which have R/W access by all EA execution units.

I just question on how safe are client terminal global variables?

Again, if client terminal crashes or the power is turned off or a dozen other possibilities for failure of client terminal, can an EA on restart and init() is called, be sure that the latest client terminal global variable content be available to it? If it cannot then it cannot reinstate it's own runtime state which was in force prior to client terminal failure... and imho means failure to deal with any outstanding trading commitments.

Of course this is endless type of question - but can you give me some indication that a restarting EA can rely on previous client terminal state prior to failure?

This is why I asked also about how the client terminal stores it's runtime environment (which I would assume also means all EAs state). If the client terminal only flushes to disk on scheduled time then there is good possibility that failure before this time results in global variable value inconsistency to what is actually happening in real time just when failure happens.

Look, I feel silly about asking simply as said above that is endless loop question because failure can happen at any time - client terminal has no control over this but without some indication of how/when client terminal is safeguarding it's environment, how can one trully rely on full-on unmonitored autobot trading EA? Is it not all about trader confidence in tools using? For sure my EA coding can be terrible and 'help' me to loose deposit ;) - but that does not have relevance to my question.

My money is on the table, yes? So I feel imho that this is important issue which unmonitored autobot will [at some time] have to deal with.