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

 
Andrey Barinov:

I understand that you have to unload to the init (or better ontik) after the change. I.e. memorise account numbers in global variables and unload if change occurs. You can also try to analyze _DeInitReason in the init() and unload.

This solution was shown. It works only if the same symbol exists after the account change.

 
fxsaber:

Please show here the source code for an EA that unloads itself when the account changes.

Do I need it? You're talking about the problem of different symbol names here.

Forum on trading, automated trading systems & strategy testing

Peculiarities of mql5, tips and tricks

fxsaber, 2020.05.20 23:09

I have a very good Expert Advisor, that should be deleted during account switching.

Suppose the Expert Advisor is running on EURUSD. It will switch to a server where symbols are prefixed. For example, EURUSD.abc.

In this case, the EA still hangs and cannot delete itself. Does anyone have a solution to this problem?


This is exactly what my answer was. If the instrument names are different in the different accounts, use the string handling functions and extract the right part of that string.
 
Igor Zakharov:

in which case is OnInit() not started?

Nothing is triggered.

Maybe at the level of OnDeinit() try to delete?

ExpertRemove() is definitely not a helper. You can try via templates. But OnDeinit is not able to detect that there has been an account change.

 
Alexey Viktorov:

Do I need it? You're talking about the problem of different character names here.

That's exactly what my answer was. If the instrument names are different in different accounts, use the string handling functions and extract the right part of that string.

You are not talking to a beginner. Don't suggest unworkable hypotheses.

 
fxsaber:

Nothing is starting up.

ExpertRemove() is definitely no help. We can try through templates. But in OnDeinit it is not possible to determine that there has been an account change.

Where ExpertRemove does not work - there is also ChartClose(). I do not understand what the problem is. What happens after the account is changed? An additional chart with Expert Advisor appears? Or it's just the current chart symbol changes? Maybe, the ChartID is changed and therefore your previous solution does not work? Ticks are processed anyway, it means that we have to unload to OnTick, if OnInit isn't working.

 
fxsaber:

You are not talking to a newcomer. Don't suggest unworkable hypotheses.

Likewise, you should not publish non-working code. And don't discuss problems encountered on the thorny path of a programmer in the topic of language features.

 
Alexey Viktorov:

In the same way, you should not publish non-working code. And don't discuss in the topic of language features the problems encountered on the thorny path of a programmer.

You are incompetent on this problem.

 

only the services are not linked to the chart. i haven't tested it, but most likely it will be able to restart after changing the account. and already from it change the templates of other charts. but in general it's strange that REASON_ACCOUNT is not caught.

but in general, it's more of a bug than a feature.

 
fxsaber:

You are incompetent on this problem.

If you are so competent, then please tell me why it does not work

REASON_ACCOUNT

6

Another account has been activated or reconnected to the trade server because of a change in account settings

 
Alexey Viktorov:

If you are so competent, then please tell me why this does not work

REASON_ACCOUNT

6

Another account was activated or reconnected to the trade server because of a change in account settings

  1. The documentation is false. You can check it manually by re-logging.
  2. There is no easy way to unload yourself.
Reason: