ShutDown by timeout using ChartApplyTemplate()

 

Hello guys,


I need a little help solving this issue.

In general, I'm trying to open a new chart and to apply template with attached EA on it.

If I try to attack a simple template without EA, everything works fine, if I try to attach template with EA, it try to open it and fail giving me "shutdown by timeout". Also applying the template manually gives no error and works fine.

Any hint how to make it works ?

Make template from ChartID. test-2 has to open the template ChartID.


Thank you in advance

Documentation on MQL5: Chart Operations / ChartApplyTemplate
Documentation on MQL5: Chart Operations / ChartApplyTemplate
  • www.mql5.com
Applies a specific template from a specified file to the chart. The command is added to chart messages queue and will be executed after processing of all previous commands. The Expert Advisor will be unloaded and will not be able to continue operating in case of successful loading of a new template to the chart it is attached to. If the...
Files:
chartID.mq4  1 kb
test-2.mq4  2 kb
ChartID.tpl  1 kb
 
neverman: trying to open a new chart and to apply template
It takes time to open a chart. Your code must wait a few seconds before applying the template.
 
William Roeder:
It takes time to open a chart. Your code must wait a few seconds before applying the template.

I set Sleep(10000) after Chartopen()

no change.


2020.03.22 16:23:36.171 Expert chartID USDCAD,M1: removed

2020.03.22 16:23:36.169 chartID USDCAD,M1: uninit reason 0

2020.03.22 16:23:36.169 chartID USDCAD,M1: shutdown by timeout

2020.03.22 16:23:33.672 chartID USDCAD,M1: initialized

2020.03.22 16:23:33.668 Expert chartID USDCAD,M1: loaded successfully

2020.03.22 16:23:33.662 Expert chartID USDCAD,M1: loaded successfully

2020.03.22 16:23:33.648 test-2 EURUSD,H1: initialized

2020.03.22 16:23:33.648 test-2 EURUSD,H1: The template ChartID.tpl applied successfully

2020.03.22 16:23:33.648 test-2 EURUSD,H1: First chart132293538622277310 NewChart= 132293606035605046

2020.03.22 16:23:23.537 test-2 EURUSD,H1: The template ADX.tpl applied successfully

2020.03.22 16:23:23.537 test-2 EURUSD,H1: First chart132293538622277310 NewChart= 132293605934491603

2020.03.22 16:23:11.551 Expert test-2 EURUSD,H1: loaded successfully

2020.03.22 16:22:30.920 Compiling '02-StartEventMoment'


 
For me, the problem comes from the delay of loading the EA. If it didn't open in 2,5 seconds, it gives this error. The question is why it load so slowly. It is 1 row code. When I do it manually, it loads instantly. 
 
neverman:
For me, the problem comes from the delay of loading the EA. If it didn't open in 2,5 seconds, it gives this error. The question is why it load so slowly. It is 1 row code. When I do it manually, it loads instantly. 

You get this problem because you are using ChartApplyTemplate() 2 times in a row.

...
long nextchart = ChartFirst(); //define the first chart
long newchartid = ChartOpen(TradePairs,1); //open new chart

ChartApplyTemplate(newchartid,usertemplate); //apply template with the given values

Print("First chart" + nextchart + " NewChart= " + newchartid);
err = GetLastError();
if(ChartApplyTemplate(newchartid,usertemplate))
  {
   Print("The template "+usertemplate+" applied successfully");
  }
...
 
Alain Verleyen:

You get this problem because you are using ChartApplyTemplate() 2 times in a row.

Genius !!! Thanks :) it works.

The proper code had to be:

bool ApplyingTemplate = ChartApplyTemplate(newchartid,usertemplate);

Print("First chart" + nextchart + " NewChart= " + newchartid);
err = GetLastError();

if(ApplyingTemplate)
  {
   Print("The template "+usertemplate+" applied successfully");
  }
else
   {
   Print("Failed to apply "+usertemplate+" , error code ",err);
   }
Reason: