There is no "option for that" because it's automatic. Uninitialization Reason Codes - MQL4 Documentation REASON_ACCOUNT
This is what I thought, but I did many tests and it seems to me that MT4 (build 765) does not reinitialize the indicators.
This is a minimal indicator to test:
//+------------------------------------------------------------------+ //| ChangeAccount.mq4 | //+------------------------------------------------------------------+ #property strict #property indicator_chart_window int OnInit() { SetIndexLabel(0, NULL); Print("Initializing. Demo? ", IsDemo()); return INIT_SUCCEEDED; } void OnDeinit(const int reason) { Print("OnDeinit, reason = ", reason, " (code REASON_ACCOUNT = ", REASON_ACCOUNT, ")"); } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { return 0; }OnInit is called only when I add the indicator or I recompile the indicator. If I double-click on another account to log in it, the indicator is not reinitialized. Why?
This is what I thought, but I did many tests and it seems to me that MT4 (build 765) does not reinitialize the indicators.
This is a minimal indicator to test:
Unlike EAs, indicators never reload with account or server change. It's been like this since I can remember. Neither there is an easy function to support reloading the indicator. You have to watch the account number yourself and recalculate the indicator if the account changes.
- Ovo: Unlike EAs, indicators never reload with account or server change. It's been like this since I can remember. Neither there is an easy function to support reloading the indicator. You have to watch the account number yourself and recalculate the indicator if the account changes.
Since indicators are based on chart's pair/TF, there is no need for them to recalculate anything. Try changing one of those and you will see a deinit/init cycle.
- ale: OnInit is called only when I add the indicator or I recompile the indicator. If I double-click on another account to log in it, the indicator is not reinitialized. Why?A deinit/init cycles is NEVER a reinitialization (recompile being the exception.) Globally/static declared variables are set once on load.
- Ovo: Unlike EAs, indicators never reload with account or server change. It's been like this since I can remember. Neither there is an easy function to support reloading the indicator. You have to watch the account number yourself and recalculate the indicator if the account changes.
Since indicators are based on chart's pair/TF, there is no need for them to recalculate anything. Try changing one of those and you will see a deinit/init cycle.
- ale: OnInit is called only when I add the indicator or I recompile the indicator. If I double-click on another account to log in it, the indicator is not reinitialized. Why?A deinit/init cycles is NEVER a reinitialization (recompile being the exception.) Globally/static declared variables are set once on load.
Also, init is no reinit? if not recompile?
It`s clear: In Spring I Like to Spring across the Spring Like a Spring.
Also, init is no reinit? if not recompile?
It`s clear: In Spring I Like to Spring across the Spring Like a Spring.
So there is not way to make MT4 call OnInit (or any other function) when an account is changed.
All I can do is check every time in OnCalculate if the account number is equal to the past account number. This makes the indicator much more slow :(
Thank you
So there is not way to make MT4 call OnInit (or any other function) when an account is changed.
All I can do is check every time in OnCalculate if the account number is equal to the past account number. This makes the indicator much more slow :(
Thank you
extern int test=0 void OnInit(){ ++test; Comment(IntegerToString(test)); }Try that and change timeframes and then recompile. What happens?
Try that and change timeframes and then recompile. What happens?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Can MT4 deinit and reinit an indicator when one changes account or server?
I have read around that there should an option for that, but I cannot find it.