The topic is about changing the account, isn't it. You turned the topic to changing timeframes, and in fact nobody complains about changing timeframes. Now, you are talking about recalculating bars. Do you really believe that recalculating more bars is the remedy for a changed account? When you start the indicator in a demo account, and then the indicator does not register that it has switched to a real account? When the indicator does not notice, that the history folder changed and keeps feeding hst file in an incorrect folder? When your indicator feeds a remote connection and does not notice the account changed? There are a dozen more reasons why you need to register the account change. The question was HOW to register the ACCOUNT CHANGE in an INDICATOR, not quarrelling about global variables in experts or recounting bars. Please accept it.
too bad that the indicator OnInit is not called when changing accounts.
The problem is that differents brokers are using different CFD symbol names for the same stock index.
So when I switch to another broker and go back to my previous broker, the indicator is not refreshing anymore and get stuck.
I am not sure that it isn't called, but if that is the case, check for it. Is that so hard?
static long AC=0; long pAC=AC; AC=AccountInfoInteger(ACCOUNT_LOGIN);
if(AC != pAC && pAC != 0) OnInit();
That is not an assignment; it's initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.
They are initialized once on program load.
They don't update unless you assign to them.
In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and
Don't try to use any price or server related functions in OnInit (or on load), as there may be no connection/chart yet:
Please enable the necessary setting in your browser, otherwise you will not be able to log in.