Features of the mql5 language, subtleties and tricks - page 178

 
Andrey Barinov:

Where ExpertRemove does not work - there is also ChartClose(). I don't understand what the problem is. What happens after the account is changed? Does it show the additional chart with the Expert Advisor? Or it's just the current chart symbol changes? Maybe, the ChartID has changed, and that's why your previous solution doesn't work. Ticks are handled anyway, it means that we need to unload them into OnTick, if OnInit isn't working.

Let's say, answered all these questions, then what? If you want to get into the subject, you can't do it without trying it on your machine.

Got to this working solution.

#include <fxsaber\Expert.mqh> // https://www.mql5.com/ru/code/19003

// Выгружает себя, если после смены счета отсутствует символ.
void OnDeinit( const int Reason )
{
  if (Reason == REASON_ACCOUNT)
  {
    MqlTick Tick;
    
    if (!SymbolInfoInteger(_Symbol, SYMBOL_CUSTOM) && !SymbolInfoTick(_Symbol, Tick))
    {
      Alert("Account is changed!");
      
      if (EXPERT::Remove())
        Alert("Expert is removed!");
      
      // ExpertRemove(); // Не поможет.
      // ChartClose();   // Не лучшее решение.
    }
//  else
      // Для кастомных и других случаев дополнить код следущим решением.
      // https://www.mql5.com/ru/forum/170952/page175#comment_16365819    
  }  
}


ZZY Required for a combat advisor.

 
fxsaber:

Please show here the source code of the EA that unloads itself when the account is changed.

The source code will be available later. Check first if this is a feature for you.

 
Alexey Viktorov:

The source code will be available later. Check first to see if these are special features for you.

It's running. Doesn't work.

2020.05.21 10:49:58.028 00 (EURUSD,M1)  Идиот
2020.05.21 10:49:58.028 00 (EURUSD,M1)  ExpertRemove() function called

Apparently, it's already a trend to use Russian words in the log.

 
fxsaber:

It's up and running. It's not working.

Apparently, it's already a trend to use Russian words in the logs.

These aren't logs. I didn't mean to offend you. I write this for myself, when something doesn't work. And then I forgot to delete it.

If that's not what you were expecting, then please excuse me. You wanted to remove the EA from the chart when you changed accounts, the EA does that. How it doesn't work for you I don't want to know.
 
Alexey Viktorov:

These are not logs. I didn't mean to offend you. This is me writing for myself when something doesn't work out. And then I forgot to delete it.

If you find a workable solution other than the one I suggested, it will be interesting to see.

 
Alexey Viktorov:

You wanted to remove the EA from the chart when you changed accounts, the EA does this.

Unfortunately, it does not.



In general, calling ExpertRemove with REASON_ACCOUNT is a completely meaningless thing.

 
fxsaber:

Unfortunately, it doesn't.



In general, calling ExpertRemove with REASON_ACCOUNT is an absolutely meaningless thing.

If you are not a beginner, you should know that the Expert Advisor only works with a chart. Without a chart only the service works. How does it work ???

 
Alexey Viktorov:

If you are not a beginner, you should know that the EA only works with a chart. Without a chart only the service works. How does it work?

You are totally incompetent in this matter, unfortunately. The working solutions offered here are the real subtlety of working and understanding how it actually works.

 
fxsaber:

You are totally incompetent in this matter, unfortunately. The working solutions suggested here are the real subtlety of working and understanding how things actually work.

Well, yes. There is only one competent person here.

 

As an option.

int OnInit(void)
{
     string name_global = "exp_account";
     if( GlobalVariableCheck(name_global) )
     {
          if( AccountInfoInteger(ACCOUNT_LOGIN) !=  GlobalVariableGet(name_global) )
               if( GlobalVariableDel(name_global) )
                    ExpertRemove();
     }
     else
          GlobalVariableSet( name_global, AccountInfoInteger(ACCOUNT_LOGIN) );

     return(INIT_SUCCEEDED);
}