Download MetaTrader 5
To add comments, please log in or register
Find out how to install MetaTrader on Linux
Fa Cao
1140
Fa Cao 2013.11.26 01:23 
A:

bool isFirst = true;
datetime  time_current;
int init(){
   if(isFirst) 
   { isFirst = false; 
    time_current=TimeCurrent();
    }
B:

extern bool isFirst = true;
extern datetime  time_current;
int init(){
   if(isFirst) 
   { isFirst = false; 
    time_current=TimeCurrent();
    }


Regarding codes 'A' and 'B', after they have been attached to a chart, the parameter, time_current, will never change when timeframe is changed (never be initiated again) in 'A', but do in 'B'; however we can set the parameter ,
time_current, when the code is attached to a chart in 'B', but we can't do like this in 'A'; (of course, the assignment when attached in this code is nonsense here, but i will in other place.)
So how to  set variables' value when EA is being attached like B and the variables can never been changed when shift time frame like in A?
Ubzen
5394
Ubzen 2013.11.26 07:10  
I do-not understand why are you using this flag. Are you trying to stop something from happening when the program goes through a de-init and re-init cycle? Is this for an indicator... is this for an expert advisor? Please list the cases you're trying to avoid by using that variable.
Ian Venner
2583
Ian Venner 2013.11.26 07:36  

If you want persistant data write it to a file or set a global variable.

Keith Watford
Moderator
9546
Keith Watford 2013.11.26 09:13  

Haven't you already covered this here?

https://www.mql5.com/en/forum/147862

Fa Cao
1140
Fa Cao 2013.11.26 10:03  
GumRai:

Haven't you already covered this here?

https://www.mql5.com/en/forum/147862


yes, i am

but this problem can't be resolve until now

so i list it here more clearly.

Ubzen
5394
Ubzen 2013.11.26 10:09  
vx0532:


yes, i am

but this problem can't be resolve until now

so i list it here more clearly.

Perhaps you should re-read the advices already given?
whroeder1
14240
whroeder1 2013.11.26 14:06  
vx0532: So how to set variables' value when EA is being attached like B and the variables can never been changed when shift time frame like in A?
When in doubt, THINK.
bool isFirst = true;           // Can't be changed by human.
extern datetime  initial_time; // Can be changed whenever, but used on first load only.
datetime  time_current;        // Can't be changed = initial_time on first load.
int init(){
   if(isFirst) 
   { isFirst = false; 
     time_current=initial_time
   }
Don't double post.
/
To add comments, please log in or register