initialize a global variable

 
Hi all,

i have a special Question to MQ4, maybe you can help me

i have a global integer Variable in an EA
if i start the Programm the Variable will be initialice to 0 (i=0)
if i call the properties and then go back via OK. The Init() will be called
but the global variable i is not initialiset to 0
the variable has allways stored the old value.

the definition of the GLOBAL variable is:
int i=0;

on Solution can be to set the Variable to 0 in init()
but is there an other way?

Thanks a lot.
Thomas
 
thomasblaesi wrote >>
Hi all,

i have a special Question to MQ4, maybe you can help me

i have a global integer Variable in an EA
if i start the Programm the Variable will be initialice to 0 (i=0)
if i call the properties and then go back via OK. The Init() will be called
but the global variable i is not initialiset to 0
the variable has allways stored the old value.

the definition of the GLOBAL variable is:
int i=0;

on Solution can be to set the Variable to 0 in init()
but is there an other way?

Thanks a lot.
Thomas

Hi,

It is a good thing we can change some parameters without loosing some data, isn't it?

So just initialize your global data in the init() and your special case will be ok. Or you can initialize your global data only when the related parameter(s) has been changed.

 


Thomas, EA source file 'global scoped variables' are not always reset to compile time values.

As you say, on program start, i is zero.

If you mean "call the properties" as in key F7 to popup EA properties window

then you will not always get EA to startup using compile time values.

.

Go over to this thread's page.5

'Interview with Stanislav Starikov: Features of New MQL5'

.

search for this string:

"12. UninitializeReason()"
.

Notice the table which will show you when/whenNot EA memory will be reset.

.

To be honest, your best bet if must have i=0 each time init() is called then put EA global variable assignments inside init()

hth

Reason: