Problem applying template

 

Hi,


I'm writing an EA.

Under Tools->Options I've set the symbol to GOLD. When the trading terminal opens I see a chart with the symbol Gold. So far so good.

In the OnInit() function I apply a ChartApplyTemplate function and nothing happens. I tried ChartApplyTemplate using the chartID and leaving it 0.

If I do a ChartOpen() and then apply  ChartApplyTemplate, it correctly applies the  template to the new opened chart. The problem with using ChartOpen() is the  chartID and _Symbol are not linked. Any Comments or chart functions only work on the chart created on start up. There appears there is no way to update _Symbol from the EA.

My question is, how to apply  the template to the chart opened when the EA starts?


Cheers,

Paul

 
pconrad:

Hi,


I'm writing an EA.

Under Tools->Options I've set the symbol to GOLD. When the trading terminal opens I see a chart with the symbol Gold. So far so good.

In the OnInit() function I apply a ChartApplyTemplate function and nothing happens. I tried ChartApplyTemplate using the chartID and leaving it 0.

If I do a ChartOpen() and then apply  ChartApplyTemplate, it correctly applies the  template to the new opened chart. The problem with using ChartOpen() is the  chartID and _Symbol are not linked. Any Comments or chart functions only work on the chart created on start up. There appears there is no way to update _Symbol from the EA.

My question is, how to apply  the template to the chart opened when the EA starts?


Cheers,

Paul

Looks like you are launching your EA from the code editor.

I would just open a new chart manually and drop the EA onto the chart; then compile the EA when you make changes.

ChartApplyTemplate won't change the symbol I don't think so you might need a separate code to do that and then apply the template.

string sym="EURUSD",templatename="mytemplate";
int period=60;
bool done;


//apply template to current chart
ChartSetSymbolPeriod(0,sym,period);
 done=ChartApplyTemplate(0,templatename);
 

//apply template to new chart
 long chart=ChartOpen(sym,period);
 done=ChartApplyTemplate(chart ,templatename);
Reason: