Very strange BUG with MT5 Build 5120 Compiler (memory overflow?)

 

Hello, since a few days I've been breaking my head over a very strange and particular issue: the same EA that always worked before build 5120, has now stopped to work, it do not open any trade into the strategy tester even if all event handlers are correctly called.

No changes into the code, just recompiled using the very last version.

After a lot of tests I did I partially isolated the problem: a very long string variable assignation (around 2500 characters). Even if that variable is totally not used inside the trading logic, just assigning it, breaks the EA and make it "silent", no errors, no actions, just silence. I also tried to remove the "Compilation optimization", as well as changing the CPU architecture, no changes and issue is still there. I also tried to switch from a single string to an array of strings, issue still there.

Unfortunately If I try to do the same string assignation inside a simple EA to recreate the issue, it do not happens.

The subject problematic EA has something like 6000+ rows of code with a lot of variables and structures.

My first and only suspect is something related to overflow or serialization, but without any log or evident other issue, it's impossible for me to troubleshoot.

The other important factor is that, once I recompile it using an old version (I tried build 4755), the EA goes back to normal activity, also on the 5120 MT5 terminal version, which leads the issue strictly related to the 5120 compiler, and not to the terminal itself.


Even if now i'm back to using the older version, I'm really scared about how many other EA I built can be affected by this issue, even if this one is the only one which have a similar "long string assignation".

Also, since some months and some builds, for this specific EA (which is probably the heaviest I have) with "compilation optimization" enabled, it takes minutes to compile.


Important note: I cannot share source code or provide a reproducible example due to strict confidentiality constraints. However, I’m reporting this issue as it only occurs after recompilation with build 5120, while the exact same code behaves correctly when compiled with older builds (like 4755). I understand that without a test case the issue is harder to validate, but I hope this can at least raise awareness, in case others are affected or already have experienced something similar.

 
Fabio Cavalloni:

Hello, since a few days I've been breaking my head over a very strange and particular issue: the same EA that always worked before build 5120, has now stopped to work, it do not open any trade into the strategy tester even if all event handlers are correctly called.

No changes into the code, just recompiled using the very last version.

After a lot of tests I did I partially isolated the problem: a very long string variable assignation (around 2500 characters). Even if that variable is totally not used inside the trading logic, just assigning it, breaks the EA and make it "silent", no errors, no actions, just silence. I also tried to remove the "Compilation optimization", as well as changing the CPU architecture, no changes and issue is still there. I also tried to switch from a single string to an array of strings, issue still there.

Unfortunately If I try to do the same string assignation inside a simple EA to recreate the issue, it do not happens.

The subject problematic EA has something like 6000+ rows of code with a lot of variables and structures.

My first and only suspect is something related to overflow or serialization, but without any log or evident other issue, it's impossible for me to troubleshoot.

The other important factor is that, once I recompile it using an old version (I tried build 4755), the EA goes back to normal activity, also on the 5120 MT5 terminal version, which leads the issue strictly related to the 5120 compiler, and not to the terminal itself.


Even if now i'm back to using the older version, I'm really scared about how many other EA I built can be affected by this issue, even if this one is the only one which have a similar "long string assignation".

Also, since some months and some builds, for this specific EA (which is probably the heaviest I have) with "compilation optimization" enabled, it takes minutes to compile.


Important note: I cannot share source code or provide a reproducible example due to strict confidentiality constraints. However, I’m reporting this issue as it only occurs after recompilation with build 5120, while the exact same code behaves correctly when compiled with older builds (like 4755). I understand that without a test case the issue is harder to validate, but I hope this can at least raise awareness, in case others are affected or already have experienced something similar.

I guess I have a similar experience, although my code wasn't tested on an older version. When I wrote a code according to what I'm sure it's the right way, the code didn't work in strategy tester, when I changed a few things it worked but not the way I expected it to work. It's frustrating.
 
Fabio Cavalloni:

Hello, since a few days I've been breaking my head over a very strange and particular issue: the same EA that always worked before build 5120, has now stopped to work, it do not open any trade into the strategy tester even if all event handlers are correctly called.

No changes into the code, just recompiled using the very last version.

Did you try to trap the real problem by means of print outs or step by step debugger? Does recompiled EA ennter the even handlers? If so, how does it skip the algorithm?

I mean that the "long" string (actually, not long at all) is just a trigger of something else, because it's not its size but other conditions that affects the code and would be great to pinpoint them.

 
Stanislav Korotky #:

Did you try to trap the real problem by means of print outs or step by step debugger? Does recompiled EA ennter the even handlers? If so, how does it skip the algorithm?

I mean that the "long" string (actually, not long at all) is just a trigger of something else, because it's not its size but other conditions that affects the code and would be great to pinpoint them.

I went back on testing with fresh mind, and finally found the error. As you correctly said, it was not related to that even if I isolated that as root cause.

Strangely, even that skipping that string assignation solved the issue in my tests, I realized that the REAL cause was related to ArrayInitialization issue (which was already pinpointed out by other people). In few words I have an array of datetime, in which I store the LastTrade time, that array is initialized at 0 during OnInit.

In 5120 version, that initialization not worked, in fact the vaule of all items of the array is simply empty, not 0, not a strange value, even not EMPTY_VALUE. So, I switched from ArrayInitialize to a FOR cycle, and all went back to normal operation.

Remain the doubt of why that string caused the issue because it was totally unrelated, but, as developers, we know that once a thing works, we should not ask ourself too much why :)


Thanks for spurring me on!