ChartApplyTemplate removes the EA

 

Hi,

The code below removes the EA after X seconds (if you try to debug it, it closes the current chart). Just create an EA with the code, run it and press T key:

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   if(id==CHARTEVENT_KEYDOWN &&
      lparam=='T')
     {
      Print("T pressed");
      if(!ChartApplyTemplate(0,"default"))
        {
         Print("Error ",_LastError);
        }
      else
        {
         Print("Template applied");
        }
     }
  }

It seems a problem with ChartApplyTemplate(). The function returns true, but something happens and it removes the EA from the chart.

I'm using version MT5 build 2994 (09 Jul 2021).

Can anyone try to reproduce it with this same version and see if the error occurs?

Here's the log (Expert+Journal):

2021.07.16 15:10:48.886 Experts expert TesteTemplate (EURUSD.,M1) loaded successfully
2021.07.16 15:10:53.852 TesteTemplate (EURUSD.,M1)      T pressed
2021.07.16 15:10:53.852 TesteTemplate (EURUSD.,M1)      Template applied
2021.07.16 15:10:55.112 Experts expert TesteTemplate (EURUSD.,M1) removed

Thank you.

 
Just an update: version MT5 build 2981 (21 Jun 2021) has the same (possible) issue.
 
Felipe Augusto Torres Maggico: The code below removes the EA after X seconds (if you try to debug it, it closes the current chart). Just create an EA with the code, run it and press T key:

It seems a problem with ChartApplyTemplate(). The function returns true, but something happens and it removes the EA from the chart. I'm using version MT5 build 2994 (09 Jul 2021). Can anyone try to reproduce it with this same version and see if the error occurs? Here's the log (Expert+Journal):

Is it not obvious that if you apply a template to the current chart, that EVERYTHING gets removed, including the EA that applied the template, and replaced by what ever the template loads (after returning from the event handler)?

 
Fernando Carreiro:

Is it not obvious that if you apply a template to the current chart, that EVERYTHING gets removed, including the EA that applied the template, and replaced by what ever the template loads (after returning from the event handler)?

I believe you are right. I'll test it.

Thank you!

 
Felipe Augusto Torres Maggico: I believe you are right. I'll test it. Thank you!
It is not a question of belief. It is the logical conclusion. When applying a template, everything gets removed and the new template applied. So, logically if the program calling the the ChartApplyTemplate is on that chart itself, it will also get removed.