Keeping data after a crash
-
Hi there!
I'm thinking about a special money management that makes calculation on each single trade profit to evaluate the risk for the next one. In order to do this, i need to act in relation to the starting account balance when the EA is attached to the chart for the first time, and i also need to always have the last trade data in a variable.
But... an EA like that needs to keep some data that can be lost in case of a system crash or if a platform restart is required for any reason.There's a way to store these data somewhere and tell the EA to read them when is restarted?
-
If you can get data from the latest trade, do that. Because you know, all trades exists even if you reinstall everything, and their data can be read.
Otherwise I don't use any kind of persistent memory in any block. There are some options - Terminal Variables (aka Global Variables in MetaTrader, or F3), data written in files or even objects on the chart. Well, there is no block to read data from files

But be careful with this idea, because there is some scenario where the strategy could fail even if you use such persistent memory. Imagine that your PC goes off for 10 minutes. But what happens if meanwhile some trade was closed by SL or TP on the server? You have data in your variables, but your data is now old and possibly dangerous for the strategy. That's why it's better to read data from the actual trades.
-
Thanks FxDreema,
i get your suggestion. Unfortunately i need at least one data (the last closed trade profit) to be stored somewhere.
I'll try to study the terminal variables or maybe i can write it in a log file and use a constant that in some ways overrides the EA if contains a value greater than 0.I'm a bit in trouble about reading the last closed trade profit. The "Check Profit" block only compares the profit with a value.
Can i use a formula with "(On trade) Event Data" - Profit, or the only way is to compare the current balance to the last balance?