Download MetaTrader 5
To add comments, please log in or register
Do you want to write a technical indicator? Find solution in MQL5 Reference!
Carl Schreiber
5927
Carl Schreiber 2015.07.14 15:30 

Hi,

I just have recognized that a list of global variables (GlobalVariableSet(..)) disappear?

At least as soon as I start the debugger the whole list is wiped out - before my code tries to request the variables or their values?

Does anybody what I can do??

Thanks in advance!

Gooly

whroeder1
13593
whroeder1 2015.07.14 16:25  
Shouldn't be:
When testing and optimizing the Expert Advisors that use global variables, keep in mind that client terminal and the Strategy Tester share common global variables. Therefore, the names of the global variables must be different from the names of the global variables used by other mql4 programs. Otherwise, it may lead to incorrect work of mql4 programs and inaccurate testing results. -- Global Variables of the Client Terminal - MQL4 Documentation
Carl Schreiber
5927
Carl Schreiber 2015.07.14 16:59  

Well I now found out it is not the debugger!

Just requesting one variable wipes out all - useful feature!

This is set by my script:


Now my EA wants to request the first two variables like:

   globNameRiskAcct = "PTC Risk Acct:"+(string)AccountNumber();
   globNameRiskMagi = "PTC Risk Magi:-548436835";
   
   bool a = GlobalVariableCheck(globNameRiskAcct),
        b = GlobalVariableCheck(globNameRiskMagi),
        c = (a) ? GlobalVariableGet(globNameRiskAcct,AccWeight) : false,
        d = (b) ? GlobalVariableGet(globNameRiskMagi,MagWeight): false;
..


After this little bit of code the List of global variables looks like:



Does this happen to anybody else?

Gooly

whroeder1
13593
whroeder1 2015.07.14 17:19  
gooly: Does this happen to anybody else?

  1. I ran this script and had no problem. You must be deleting variables elsewhere.
    void OnStart(){  
    string   globNameRiskAcct = "A1";   double AccWeight;
    string   globNameRiskMagi = "B2";   double MagWeight;
       
       bool a = GlobalVariableCheck(globNameRiskAcct),
            b = GlobalVariableCheck(globNameRiskMagi),
            c = (a) ? GlobalVariableGet(globNameRiskAcct,AccWeight) : false,
            d = (b) ? GlobalVariableGet(globNameRiskMagi,MagWeight): false;
    PrintFormat("a=%i, b=%i c=%i, d=%i, aw=%f, mw=%f", a,b,c,d, AccWeight, MagWeight);
    
    2015.07.14 13:16:17.404    tests EURUSD,H1: uninit reason 0
    2015.07.14 13:16:17.404    tests EURUSD,H1: a=1, b=1 c=1, d=1, aw=1.000000, mw=2.000000
  2. Build 840
Carl Schreiber
5927
Carl Schreiber 2015.07.14 17:54  

I found it:

A function called in OnDeInit() contains GlobalVariablesDeleteAll() that deletes all global variables.

But now I don't understand why the global variables were deleted at the start of this EA and before OnInit() was executed?

OnDeInit() shouldn't have been touched at all at this moment!

Thank you!

Gooly

/
To add comments, please log in or register