MQL4 EA keeping state?

 

Hi,

I have encountered a very odd behavior of an EA in MQL4. So the EA is attached to a given chart and a UI pops us which allows the user to interact with the UI(press buttons, view stats, etc).

Once the UI is closed the EA is removed using ExpertRemove() function which then triggers DeInit and the reason code is 0 and everything is fine up to this point. If I attach the EA again to the same chart or to any other chart it basically performs all button clicks that were done the first time when the EA was attached to a chart. So I don't quite understand how and why it keeps the state of what happened in the previous run of the EA.

The UI is written in C#, there is a dll which passes data from and to Metatrader based on the user interaction.

Any idea?

 

Problem solved but I can only guess as to why the state is kept.

The solution was to reset variables, arrays and other data structures in the dll once the EA is terminated.

 
persistent storage (files or GV
 
The EA calls functions from a dll and when the EA is terminated and started again the dll functions return data that was generated during the previous EA run. So I think that the dll functions are imported only once rather than every time the EA reboots.