Can External variables be changed by code?

 

Can external variables be set by code within the EA and hold that new value when closed and reopened, like export and import? I will be running an EA on a VPS which automatically restarts all EAs after an unscheduled shutdown. In this case I need to hold a variable and restablish the same value in the program on restart. The EA trades once a day of the breakout of a range. A variable is set to indicate a trade for the day has been taken. Without that variable, a trade could be taken a long way from the breakout likely on a retrace. Make sense?

 
"Can external variables be set by code within the EA"

yes

they are used just same as normally declared global scoped variables. Read and Write. Obvious differences are when F7 used and externals can now be altered and will be available to the program.


"..and hold that new value when closed and reopened, like export and import? "
no
when program closed --> reopened/run on a chart, the external variables are loaded with compile time values (your own if used or default values assigned by compiler)
an idea: you could detect when externals have been modified in your code and dump them to disc file and on restart suck them back in...
on reopening code would need to know IF should be updating externals from a file or not. One simple way would be the existence or not of the file.
eg, no updates made = no file created.
 
bluesman:

Can external variables be set by code within the EA [...]

Potentially dangerous if not done properly -> https://www.mql5.com/en/forum/123535.
 
gordon:
Potentially dangerous if not done properly -> https://www.mql5.com/en/forum/123535.
In case anyone wastes time trying to go down the following route... An EA's parameters are stored in the .chr file for its chart. However, modifying that from the EA doesn't work (and isn't easy anyway). The .chr file gets overwritten by MT4 after the EA is unloaded.
 
fbj:
"Can external variables be set by code within the EA"

yes

they are used just same as normally declared global scoped variables. Read and Write. Obvious differences are when F7 used and externals can now be altered and will be available to the program.


"..and hold that new value when closed and reopened, like export and import? "
no
when program closed --> reopened/run on a chart, the external variables are loaded with compile time values (your own if used or default values assigned by compiler)
an idea: you could detect when externals have been modified in your code and dump them to disc file and on restart suck them back in...
on reopening code would need to know IF should be updating externals from a file or not. One simple way would be the existence or not of the file.
eg, no updates made = no file created.

My original idea was as you suggest, to 'Export" and then "Import" but it was suggested to me that maybe external values would overwrie their original compiled values. Since that is not the case, export and import sound good. My question then is, what is the function or command in MQL to do this??
 
bluesman:
[...] Since that is not the case, export and import sound good. My question then is, what is the function or command in MQL to do this??
There's no built-in facility. You need to build one yourself via file functions.