
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I have written a custom indicator which imports a libraries that I have also written.
If I attach the indicator to a chart it works fine. If I recompile the indicator it deinitializes the indicator on the chart and the imported library used by the indicator, as expected.
However, if I just change the imput properties of the indicator the indicator reinitializes but the imported library do not.
Because the imported library does not reinitialize the static variables within library retain their values. This causes the indicator to go awry since I would expect if the indicator is reinitialized for any reason then any imported libraries (and their static variables) would also be reinitialized.
To reiterate, if I do a recompile of the indicator the indicator and its imported library all reinitialize fine.
If I change the input properties of the indicator the indicator reinitializes but the imported library does not.
Here is an example: a very simply library called afunclib.mq4...cut and paste the library and compile a library called afunclib.ex4 with it.
// AFUNCLIB.MQ4
#property library
int starttik;
int init() {
Print("afunc(): library initialized");
starttik = GetTickCount();
return (0);
}
int deinit() {
Print("afunc(): library deinitialized");
return (0);
}
void afunc() {
Print("afunc(): running for "+DoubleToStr(((GetTickCount()-starttik)/1000.00),2)+" seconds");
}
Now a very simple indicator called AFUNC.MQ4 that displays nothing on the chart but calls the AFUNCLIB.EX4 library.
// AFUNC.MQ4
#property indicator_chart_window
extern int debug;
#import "afunclib.ex4"
void afunc();
#import
int init() {
return (0);
}
int deinit() {
return (0);
}
int start() {
afunc();
return(0);
}
If you attach AFUNC4.EX4 to any chart the experts tab will display the output of the indicator.
You will see that the afunc() function is called and it keeps a count of how long has elapsed since it was last called via a static variable called 'starttik'.
If you select from the menu bar "Charts...Indicators" and modify the input parameters of AFUNC you will see that although the indicator itself reinitializes the AFUNCLIB library does not. As a result the 'starttik' variable in the AFUNCLIB library is not reset and the counter continues unabated.
Hope someone can shed some light on this. I would expect that if the main indicator is reinitialized then any imported libraries would also reinitialize. This does not seem to be the case.
Best wishes,
Laurence.