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

 
fxsaber:

ExpertRemove has not been called.

I see. What's stopping you from handling the deinitialisation codes? They have just the account change in them.

 
Artyom Trishkin:

I see. What's stopping you from handling the deinitialisation codes? They have just the account change in them.

Forum on trading, automated trading systems and strategy testing

Peculiarities of mql5, tips and tricks

fxsaber, 2021.06.30 15:45

You should try it. There's a long discussion on this topic at the link above.

ExpertRemove in OnDeinit is an almost meaningless construct.
 
fxsaber:
ExpertRemove in OnDeinit is an almost meaningless construct.

How confusing :)

Have you tried looking at deinitialisation codes in OnInit()?

Документация по MQL5: Предопределенные переменные / _UninitReason
Документация по MQL5: Предопределенные переменные / _UninitReason
  • www.mql5.com
_UninitReason - Предопределенные переменные - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Artyom Trishkin:

Have you tried looking at the deinitialisation codes in OnInit()?

Studied the question seriously. If you want to understand how it works architecturally, you can't do it without trying.

 
fxsaber:

Give it a try. There's a long discussion on the subject at the link above.

I don't see the problem. The moment of account change is highlighted in yellow.

long prev_account = 0;

int OnInit(void)
{
        prev_account = AccountInfoInteger( ACCOUNT_LOGIN );
        EventSetTimer(1);

        Print( "Initialization on account #", AccountInfoInteger( ACCOUNT_LOGIN ) );
        return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
        Print( "Deinitialization on account #", prev_account );
        prev_account = 0;
        EventKillTimer();
}

void OnTick(void)
{
        if ( AccountInfoInteger( ACCOUNT_LOGIN ) != prev_account ) return;

        Print( "New tick on account #", AccountInfoInteger( ACCOUNT_LOGIN ) );
}

void OnTimer(void)
{
        if ( AccountInfoInteger( ACCOUNT_LOGIN ) != prev_account ) return;

        Print( "Timer on account #", AccountInfoInteger( ACCOUNT_LOGIN ) );
}
2021.07.01 11:53:13.404 test (USDCHF,M5)        Initialization on account #30966228
2021.07.01 11:53:14.404 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:15.404 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:16.404 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:17.405 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:18.405 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:19.405 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:20.405 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:21.405 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:22.405 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:23.405 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:24.405 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:25.405 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:25.904 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:26.419 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:27.097 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:27.214 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:27.338 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:27.416 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:27.470 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:27.574 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:27.682 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:28.282 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:28.407 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:28.408 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:29.099 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:29.411 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:29.507 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:29.644 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:29.873 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:30.234 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:30.405 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:30.449 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:31.238 test (USDCHF,M5)        New tick on account #30966228
2021.07.01 11:53:31.410 test (USDCHF,M5)        Timer on account #30966228
2021.07.01 11:53:31.720 test (USDCHF,M5)        Deinitialization on account #30966228
2021.07.01 11:53:32.226 test (USDCHF,M5)        Initialization on account #42821331
2021.07.01 11:53:33.225 test (USDCHF,M5)        Timer on account #42821331
2021.07.01 11:53:33.338 test (USDCHF,M5)        New tick on account #42821331
2021.07.01 11:53:33.689 test (USDCHF,M5)        New tick on account #42821331
2021.07.01 11:53:34.220 test (USDCHF,M5)        Timer on account #42821331
2021.07.01 11:53:35.220 test (USDCHF,M5)        Timer on account #42821331
2021.07.01 11:53:36.220 test (USDCHF,M5)        Timer on account #42821331
2021.07.01 11:53:36.511 test (USDCHF,M5)        New tick on account #42821331
2021.07.01 11:53:36.624 test (USDCHF,M5)        New tick on account #42821331
2021.07.01 11:53:36.728 test (USDCHF,M5)        New tick on account #42821331
2021.07.01 11:53:37.157 test (USDCHF,M5)        New tick on account #42821331
2021.07.01 11:53:37.220 test (USDCHF,M5)        Timer on account #42821331
2021.07.01 11:53:37.391 test (USDCHF,M5)        New tick on account #42821331
2021.07.01 11:53:37.862 test (USDCHF,M5)        New tick on account #42821331
2021.07.01 11:53:37.960 test (USDCHF,M5)        New tick on account #42821331
2021.07.01 11:53:38.210 test (USDCHF,M5)        New tick on account #42821331
2021.07.01 11:53:38.225 test (USDCHF,M5)        Timer on account #42821331
2021.07.01 11:53:38.340 test (USDCHF,M5)        New tick on account #42821331
2021.07.01 11:53:38.571 test (USDCHF,M5)        New tick on account #42821331
2021.07.01 11:53:39.227 test (USDCHF,M5)        Timer on account #42821331
2021.07.01 11:53:40.227 test (USDCHF,M5)        Timer on account #42821331
2021.07.01 11:53:40.689 test (USDCHF,M5)        Deinitialization on account #42821331
 
Andrey Khatimlianskii:

I don't see the problem. The moment of account change is highlighted in yellow.

Was it possible to unload the EA at the account change in this way?

 
fxsaber:

So did you manage to unload the EA when changing account?

Did not solve the problem of unloading, solved the problem with unnecessary alerts (working on the wrong account):

Peculiarities of mql5 language, tips and tricks

fxsaber, 2021.06.30 14:01

This Expert Advisor alerts when I switch accounts. It would seem that it should not do so according to the rule

However, it happens because of the timer.

 
Andrey Khatimlianskii:

Didn't solve the unloading problem, solved the problem with unnecessary alerts (work on the wrong account):

Alert needed - to show what's going on. Demonstrates a feature.

 

Charts opened by the Tester.

<chart>
tester=1
 
How do I know the take profit and stop loss of a position in the history?