Variable problem in indicator

 
Hello,

I have a little problem that I dont understand.

After you put a indicator script on the chart and kompiler the code at the editor, one initialization is make, then when you shut down the terminal and restart again no new initialization is make.

I declare one variables of the int typ in a indicator file, above at the beginning of the code just under the #property values outside the start() function.

Then in the start() function I change the value of the variable an let print them to see whats in. Then I shift down the terminal and after a few moments I start the terminal.exe again and I recognize that the variable value dont have been reset by shut down the terminal and start again, because I see it in the Print() issue.

The example:
#property copyright "Me"
#property link      "Me"

int one;
//---
int init() {
return(0);
}
//---
int deinit(){
return(0);
}

//---
start(){

Print("#",one);
one=1;
Print("#",one);

}



At the beginning it will print 0 and then 1, and at all other times the start function is called it will print just 1 for both print issues.

But if you shut down the terminal and restart again I have think that the variable one must be first 0 and then again 1 becaues in the head its write int one; and if all variables will be reset after restart it must been like I think but it dosent.

Now in my indicator that I want to build the variables all must been reset after the terminal is restart, is there a solution?

 
There is no relation to the terminal restart actually. The initialisation mechanism is a bit different.

First of all there are two kinds of initialisation - compilation time and run time.

When you define a global scope variable the compiler puts it in static memory that is initialised with default values every time when program (either script or EA or indicator) is loaded into memory. Of course it's loaded when the terminal restarts too.

Another and more reliable way is a run time initialisation.
Initialise your global scope variables explicitly in init() function.
That'll make sure that the variables are always initialised, even if the program is not reloaded before initialisation that can happen if you change chart timeframe for instance.
 
I have establish now that the Problem is that I dont had know before that the start() function only run after restart terminal once before shut down.

However I must leran still more at all.
Reason: