sqx EA deleting other EA Global Variables

All my global variables of my other non SQX EA  that had a "_" in the title disappeared and I think I see why....

      if(GlobalVariableCheck(variableName)){          int endPos = StringFind(variableName, "_");          if(endPos <= 0) continue;   

Any global with a _ in the name will not do the continue so it will carry on...

bool variableUsed = false;                    for(int i=0; i < OrdersTotal(); i++) {             if(OrderSelect(i, SELECT_BY_POS) == true) {                if(OrderTicket() == ticketNo){                   variableUsed = true;                   break;                }             }          }

Only if the name matches the ticket will variableUsed be true.


         if(!variableUsed){             if(GlobalVariableDel(variableName)){                deletedCount++;             }

This will delete any global variables at all unless they are for an open position of only this EA!!!

Do we really need to delete them? They expire after a couple weeks I believe. If we really need to keep them clean then you will have to incorporate the magic number in to the title and check for that instead of just checking for the _ character! 

No attachments
  • Votes +2
  • Project StrategyQuant X
  • Type Bug
  • Status Fixed
  • Priority High




12.07.2019 03:39

Task created



12.07.2019 03:39
Voted for this task.


12.07.2019 03:55
This means you can't run two or more sqx generated EA on the same account without being effected by this bug btw!



13.07.2019 03:36

Subject changed from Global Variables of other EA being deleted by the sqx mql4 code to sqx EA deleting each others Global Variables if running more than one sqx EA on one account. Looks like GV are critical for many functions!



13.07.2019 14:33
To be clear this bug will cause an EA back-test to behave differently from the same EA on a live account. If you happen to have more than one EA on one account, they interfere with each other. Many of the sqx ea functions seem to be reliant on global variables but when you have more than one EA on an account then they (occasionally – once randomly every 20+ hours per EA) delete each others GV. GV seem to be used for important functions such as trailing stop and timed exits! How frequently such interference happens depends on how many EA you have on one account…


13.07.2019 14:47
Temporarily, I suggest we remove this:

   if(!IsTesting() && !IsOptimization()) {                                                initTimer();    }

This will prevent the timer from being set which in turn will prevent the GV from being deleted of other EA. The GV will eventually expire anyways.



13.07.2019 17:05
It seems to make more sense to reverse the  "!IsTesting() && !IsOptimization()" logic in this condition. Maybe SQ team meant to clean GV during testing to reduce memory usage during testing. Maybe the SQ team didn't mean to clean GV on a live account because they will expire naturally on a live account anyways. Maybe the SQ team didn't mean to clean the GV on a live account because the cleaning function is deleting all the other EA GV. If all this is true then that logic should be reversed. As it is right now we ONLY clean GV during live usage and not during testing....


13.07.2019 17:14
Voted for this task.


13.07.2019 17:30
oops false alarm!

for(int i=0; i < OrdersTotal(); i++)

We are checking the entire account for open orders, not just the EA orders. Therefore we aren't deleting other sqx ea GV after all. 

We are deleting other non sqx EA GV though if they contain a "_" .



13.07.2019 17:32

Subject changed from sqx EA deleting each others Global Variables if running more than one sqx EA on one account. Looks like GV are critical for many functions! to sqx EA deleting other EA Global Variables



14.07.2019 22:42
It does seem resource intensive to cycle through all the potential 1000's of orders of the entire terminal WITHIN another loop that is cycling through potentially hundreds of GV...

Why not use static GV names like for instance if magicnumber is 1234:
could store a ticket number of a current tracked order
could store variables of the order this way.
could store a second ticket number for a second tracked order etc. etc.

We can avoid the giant loop inside the giant loop, avoid potentially accidentally deleting other GV because of bugs.

Tomas Brynda

05.08.2019 16:05

Status changed from New to Fixed

I modified the global variables checking. Random 8 character string ID is generated into strategy's MQL code and this ID prefixed with "sq" is then checked when looping through variables.

So other EA's variables will remain untouched and each SQ EA will delete only old variables of its own.

Looping should not be very resource intensive as we are checking only pending orders and active positions and the checking interval is approximately 1 day.

Votes: +2

Drop files to upload


choose files

Max size: 5MB

Not allowed: exe, msi, application, reg, php, js, htaccess, htpasswd, gitignore

Wait please