Save variables/constants if terminal closes/crashes
-
Recently I have seen many people asking how to have the EA to remember the values that were used before.
This link will show how to achieve this, this is for constants, but a variable can be stored in the same way, and MT5 is the same:
might not work as needed, see below
https://fxdreema.com/shared/tnu6XI6odI had a thought that in a crash this might not work, so I added variables and set them to amend oninit
-
Very useful, as usual. But shouldn't those blocks be on the 'on deinit' tab instead? Why updating the values all the time and not only when the platform crashed/disconnected?
-
If the value changes the global is updated, this way if the value is changed at any time the latest value is saved, so if the platform crashes and deinit isn't activated, the value is already saved.
-
Thank you very much for this useful information. What I find very unfortunate is that the default variables are not saved and are lost when the terminal crashes. But fortunately, there are solutions from the community.
-
-
Thank you for the information. Do you mean that when I set a condition, it must be connected to the terminal variable block?
-
I use a different approach by creating text label objects on the chart in a location that is not visible. These text labels will hold the variables, flags, etc. If my MT4/MT5 crashes and I reload the EAs to the same chart, it will look for those text labels to retrieve the data and continue working.
-
@rouzbehali This is a very interesting approach. Can you share an example? I am still quite new to the subject and am grateful for any opportunity to further develop myself.
-
@tswaldi https://fxdreema.com/shared/srfHv6Ksc
Here's a link to an example project. When EMAs cross up, this EA buys, and when they cross down, it sells. After the buy trade, it assigns the variable "Buy". After selling, it assigns the variable "Sell" and creates a text far away from the corner (1000000 pixels). This text stores the variable value. If your metatrader crashes or you accidentally remove the ea from the chart, simply reload the ea. On init, ea looks for the text. If the text is discovered, ea fills retrieves the variable by checking into the text description. -
@rouzbehali Thanks for the example. I think it is really the simpler solution. I have understood the logic and will try to integrate it into my EA soon to test it in practice. I will report on the success.
-
Hello @jstap Thank you very much for your work, I´m little newbie and I have a question, what exactly should I put in the "Text (code imput): "GDIST"+"Magic "+MagicStart+"Acc "+AccountNumber(), exactly like this? Or maybe as I understand tehe same but with my account number like: "GDIST"+"Magic "+MagicStart+"Acc "+XXXXXX?
-
This depends on what you want to record, every+ means save the next data, things like AccountNumber() are standard meta trader functions that return your account number, MagicStart is the built in function in FX Dreema that returns your current EA's magic number (the one you see in your inputs), things like "Acc " is just so in the global terminal what things are is shown by the comment.
-
I tried to do this just to check if works to save the variables correctly. I guess I'm doing something wrong but I'm don't know what exactly
https://fxdreema.com/shared/GrBXfdQ2b
