Expert containing CAppDialog is crashing when changing

 

Hi all!

I'm coding an expert using CAppDialog where I'm displaying some information for the user.

It's working well but I noticed that when I change a variable in the configuration for the timeframe for candle period in the chart, the expert is suddenly exiting. This happens only for this parameter, nothing weird happens when I change any other parameter. It works well even if I change the tradesymbol.

If I set the variable to use the default timeframe = PERIOD_CURRENT and change the timeframe using the MT5 toolbar, it also works well.

I also removed all references for the panel (CAppDialog) and I run the same tests. Everything worked fine.

From my description it looks like it might be something related to the call for ChartSetSymbolPeriod(). Am I using it incorrectly? Is something I need to take tare when using it with CAppDialog?

Any help is really appreciated...
Thanks!

>> This is the code snippet where this configuration is applied.

------------

    if (TradeSymbol == "") gSymbol = _Symbol; else gSymbol = TradeSymbol;
    ChartSetSymbolPeriod(0, gSymbol, TimeFrame);
    if(!m_symbol.Name(gSymbol)) { // sets symbol name
        Print(MyName, "> " + __FILE__," ",__FUNCTION__,", ERROR: CSymbolInfo.Name");
        return(INIT_FAILED);
    }
    // Set magic number to trade object
    if (MagicNumber<=0) {
        Print(MyName, "> Magicnumber <= 0");
        return (INIT_PARAMETERS_INCORRECT);
    }
    trade.SetExpertMagicNumber(MagicNumber);

------------  This is the output from the expert log

>> Expert log output

<< Changing period for a moving average... >> -- OK

2024.08.02 00:16:29.972 ALT_TestCode (WINQ24,M5) Entering OnDeinit() with reason: 5

2024.08.02 00:16:29.972 ALT_TestCode (WINQ24,M5) Releasing hndlMA1

2024.08.02 00:16:29.972 ALT_TestCode (WINQ24,M5) Releasing hndlMA2

2024.08.02 00:16:29.972 ALT_TestCode (WINQ24,M5) Releasing hndlMaFilter

2024.08.02 00:16:29.972 ALT_TestCode (WINQ24,M5) Releasing hndlBBFilter

2024.08.02 00:16:29.978 ALT_TestCode (WINQ24,M5) Exiting OnDeinit()

2024.08.02 00:16:29.979 ALT_TestCode (WINQ24,M5) Entered OnInit()

2024.08.02 00:16:29.979 ALT_TestCode (WINQ24,M5) ALT_TestCode> Ref candle != current candle. Analyzing @ opening of ref candle

2024.08.02 00:16:29.987 ALT_TestCode (WINQ24,M5) ALT_TestCode> EMA Fast :: Applying WINQ24 timeframe: PERIOD_CURRENT and period: 9

2024.08.02 00:16:29.987 ALT_TestCode (WINQ24,M5) ALT_TestCode> EMA MEdium :: Applying WINQ24 timeframe: PERIOD_CURRENT and period: 20

2024.08.02 00:16:30.203 ALT_TestCode (WINQ24,M5) Exiting OnInit() with INIT_SUCCEEDED


<< Changing chart timeframe... >>  -- Exiting expert

2024.08.02 00:16:51.657 ALT_TestCode (WINQ24,M5) Entering OnDeinit() with reason: 5

2024.08.02 00:16:51.657 ALT_TestCode (WINQ24,M5) Releasing hndlMA1

2024.08.02 00:16:51.657 ALT_TestCode (WINQ24,M5) Releasing hndlMA2

2024.08.02 00:16:51.657 ALT_TestCode (WINQ24,M5) Releasing hndlMaFilter

2024.08.02 00:16:51.657 ALT_TestCode (WINQ24,M5) Releasing hndlBBFilter

2024.08.02 00:16:51.661 ALT_TestCode (WINQ24,M5) Exiting OnDeinit()

2024.08.02 00:16:51.662 ALT_TestCode (WINQ24,M5) Entered OnInit()

2024.08.02 00:16:51.662 ALT_TestCode (WINQ24,M5) ALT_TestCode> Ref candle != current candle. Analyzing @ opening of ref candle

2024.08.02 00:16:51.947 ALT_TestCode (WINQ24,M5) ALT_TestCode> EMA Fast :: Applying WINQ24 timeframe: PERIOD_M15 and period: 9

2024.08.02 00:16:51.963 ALT_TestCode (WINQ24,M5) ALT_TestCode> EMA MEdium :: Applying WINQ24 timeframe: PERIOD_M15 and period: 20

2024.08.02 00:16:51.982 ALT_TestCode (WINQ24,M5) Exiting OnInit() with INIT_SUCCEEDED

... It was OK untill here. I have no idea why it is entering OnDeinit() again...

2024.08.02 00:16:51.982 ALT_TestCode (WINQ24,M5) Entering OnDeinit() with reason: 3

2024.08.02 00:16:51.982 ALT_TestCode (WINQ24,M5) Releasing hndlMA1

2024.08.02 00:16:51.982 ALT_TestCode (WINQ24,M5) Releasing hndlMA2

2024.08.02 00:16:51.982 ALT_TestCode (WINQ24,M5) Releasing hndlMaFilter

2024.08.02 00:16:51.982 ALT_TestCode (WINQ24,M5) Releasing hndlBBFilter

2024.08.02 00:16:52.131 ALT_TestCode (WINQ24,M5) Exiting OnDeinit()


 
alissonveras:

Hi all!

I'm coding an expert using CAppDialog where I'm displaying some information for the user.

It's working well but I noticed that when I change a variable in the configuration for the timeframe for candle period in the chart, the expert is suddenly exiting. This happens only for this parameter, nothing weird happens when I change any other parameter. It works well even if I change the tradesymbol.

If I set the variable to use the default timeframe = PERIOD_CURRENT and change the timeframe using the MT5 toolbar, it also works well.

I also removed all references for the panel (CAppDialog) and I run the same tests. Everything worked fine.

From my description it looks like it might be something related to the call for ChartSetSymbolPeriod(). Am I using it incorrectly? Is something I need to take tare when using it with CAppDialog?


The issue is not with changing the timeframe, the issue is that doing so will cause OnDeinit() to be called. So depending how you have coded to survive a restart various problems will occur especially with CAppDialog objects. 

You need to code to ensure that settings are preserved and reinstated during changes and restarts, that may mean destroying the panel and recreating it.