What are the methods to retain a variable value if mt4 was restarted?
Global variables will be lost !
use
FileWrite()
To store your data then use FileRead(datatype) to read the data back into the EA. https://www.mql5.com/en/docs/files
A simple check call for:
ENUM_TERMINAL_INFO_INTEGER
Identifier |
Description |
TERMINAL_CONNECTED |
Connection to a trade server |
Can alert you when the connection drops.
*NOTE that comments can change !!, it's not a secure or reliable solution.

- www.mql5.com
Global variables will be lost !
use
To store your data then use FileRead(datatype) to read the data back into the EA. https://www.mql5.com/en/docs/files
A simple check call for:
ENUM_TERMINAL_INFO_INTEGER
Identifier |
Description |
TERMINAL_CONNECTED |
Connection to a trade server |
Can alert you when the connection drops.
*NOTE that comments can change !!, it's not a secure or reliable solution.
hi
is this function going to write to an external file and read back later?
hi
is this function going to write to an external file and read back later?
No that will alert you that your terminal has lost it's connection.
Can be used in combination with
Alert() PlaySound() MessageBox() SendNotification() SendMail()
And etc.
To store your data use
FileWrite()
To read it
Reads arrays of any type except for string from the file of the BIN type |
|
Reads from the file of the CSV type a string from the current position till a delimiter (or till the end of a text line) and converts the read string to a value of bool type |
|
Reads from the file of the CSV type a string of one of the formats: "YYYY.MM.DD HH:MM:SS", "YYYY.MM.DD" or "HH:MM:SS" - and converts it into a datetime value |
|
Reads a double value from the current position of the file pointer |
|
Reads a float value from the current position of the file pointer |
|
Reads int, short or char value from the current position of the file pointer |
|
Reads a long type value from the current position of the file pointer |
|
Reads from the file of the CSV type a string from the current position till a delimiter (or til the end of a text line) and converts the read string into double value |
|
Reads a string from the current position of a file pointer from a file |
|
Reads the contents from a binary file into a structure passed as a parameter, from the current position of the file pointer |
As per: https://www.mql5.com/en/docs/files
You have several options.
* Build an EA that simply scans all orders upon initialization, and handles it from there.
That will work anytime and with all positions, but you can not recover exact information about specific symbols, it means all orders will be handled to a set of pre defined values.
Unless you specify the settings, for each symbol, and load them upon detection.
* Store the current position data into a file then read that data back into the EA in case of a failure.
This requires that you FileWrite every parameter you want your EA to recover upon re-loading the terminal.
* Decentralized nodes.
In this case you run several terminals with the same software and they share a combined file.
If one terminal fails this is not a problem because there are more running on the same account.
This requires an even deeper or synchronized level of coding.(as Nodes)

- www.mql5.com
Global variables will be lost !
This is incorrect. Global variables are retained between restarts. They are just a simple way of storing data in a special file the terminal maintains for you.
Please restart your computer and try again.
Which files are they stored in?
Are you referring to a file on disk ?
or to a virtual memory location ?
It seems to me that Bob is looking for a solution that will work even in case his fuse trips because the dishwasher had an internal short circuit for example.
Please restart your computer and try again.
Which files are they stored in?
Are you referring to a file on disk ?
or to a virtual memory location ?
It seems to me that Bob is looking for a solution that will work even in case his fuse trips because the dishwasher had an internal short circuit for example.
Please restart your computer and try again.
Which files are they stored in?
Are you referring to a file on disk ?
or to a virtual memory location ?
It seems to me that Bob is looking for a solution that will work even in case his fuse trips because the dishwasher had an internal short circuit for example.
You can read this link :
Global variables are kept in the client terminal for 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.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
What are the methods to retain a variable value if mt4 was restarted?
i can only think of either
1. storing the information in the comment of an order
2. save the info in a csv file and read it back later
Thanks