Two dimensional Array not assigning values ! - page 2

 
mor707:
...

So my question is actually:  What happens with the information saved in my struct  went the following happens:

  1. I change time frame of the chart on which my EA is running,
  2. I open the "properties" window of my EA and close the "properties" box without making any changes,
  3. I open the "properties" window of my EA, changes some of the "Inputs" and close the "properties" box,
  4. If my MT4 platform loses its connection to the broker's server for a while and then re-connects.

So, I just want to know what can happen that will cause my array struct to loose the values that are stored in it when the above happens while the EA is running.

With EA nothing is lost in both the 4 cases. All variables are preserved.

 
nicholi shen:

Any time your EA is removed due to any condition, including but not limited to re-initialization, all data structures are also destroyed. The only way to prevent this is to use an object and implement logic to serialize its data and save it to a file so when the EA comes back up it will be able to load in the previously saved state.   

That's not exact.

Global/static data (using structure or not) are not destroyed as long as the EA remains on the chart.

 
Alain Verleyen:

That's not exact.

Global/static data (using structure or not) are not destroyed as long as the EA remains on the chart.

They're not perfectly preserved either... I've had some unexpected consequences (complex objects) with the assumption that they were. Best to explicitly destroy them and reinitialize them with saved data if your program depends on a persistent state.  

 
kypa:

While this is indeed the proper way there is another - saving into a chart object. It can keep data through timeframe change and terminal (and PC) restart, it will save some disk read and write compared to file write, but it will lose data if terminal is not properly exited.

I've seen this "lifehack" before but it seems like more work. Do you have an example?

 

I used it on a multitimeframe arrow indicator with sound and background-change alert. I saved played and disabled alerts in invisible arrow objects named prefix+timeframe+time. It's not that much work, but definitely an overcomplication of logic. And only advantage is less reads and writes, which would be valid advantage if it needs thousands of entries per day, so in most cases definitely not a better alternative. But still a possible way, hence the need to be shared.

I've probably deleted the code as I can't find it anywhere. It was an interesting example of "innovations", although a total mess.

 
nicholi shen:

They're not perfectly preserved either... I've had some unexpected consequences (complex objects) with the assumption that they were. Best to explicitly destroy them and reinitialize them with saved data if your program depends on a persistent state.  

If that's really the case that would be a bug and should be reported to Metaquotes.

 
Alain Verleyen:

If that's really the case that would be a bug and should be reported to Metaquotes.

lol, how? 

 
nicholi shen:

lol, how? 

With a testcase code and eventually all needed information to reproduce it. You can publish it in this topic https://www.mql5.com/en/forum/289237

I will help to reproduce it and submit it to Metaquotes (through Russian forum and personal contacts). 

MetaTrader 4 platform beta build 1145
MetaTrader 4 platform beta build 1145
  • 2018.11.09
  • www.mql5.com
MetaTrader 4 update will be released on November 9, 2018 in beta mode. The update fixes errors and improves the platform stability...
 

Just a thank you to everyone who took the time to reply to my question.

Thanks,

Christoff