ReInit indicator when account changes - page 2

 
If the timeframe changes if has to reinit to recalculate all bars. You had to see the comment go from 0 to 1. If you refuse to answer questions and perform tests, no one here can help you.
 
WHRoeder:
If the timeframe changes if has to reinit to recalculate all bars. You had to see the comment go from 0 to 1. If you refuse to answer questions and perform tests, no one here can help you.

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.

 
Ovo: The topic is about changing the account, isn't it. The question was HOW to register the ACCOUNT CHANGE in an INDICATOR
  1. It was but I was responding to
    tara: Also, init is no reinit? if not recompile?
    A deinit/init cycle is not a reload.
  2. You answered that nothing happened, which is false.
  3. Had you tried it, you would know about reload, and cycles, and whether an account change triggers one.
  4. There is nothing to register, there are no functions that register. Either an account change triggers it, or it does not.
  5. If not do what ale suggested and/or complain to Metaquotes.
    1. Can someone please advise where I send a Request for Support to Metaquotes. - MQL4 forum
    2. Get in touch with developers using Service Desk! - MQL5 forum
    3. Report it to the service desk. 'MQL5.community - User Memo' - an article about the algorithmic/automated trading in MetaTrader
    4. Report it to the Service Desk, not us users.
 

Hi


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.

 
Philippe Pauleau: too bad that the indicator OnInit is not called when changing accounts.

I am not sure that it isn't called, but if that is the case, check for it. Is that so hard?

int OnCalculate(…){
   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++.

  1. They are initialized once on program load.

  2. They don't update unless you assign to them.

  3. 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:

    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
Reason: