要先打开一个窗口。
模板引用
if(FileIsExist("my_template.tpl")) {
Print("The file my_template.tpl found in \Files'");
if(ChartApplyTemplate(0,"\\Files\\my_template.tpl")) {
Print("The template 'my_template.tpl' applied successfully");
ChartRedraw();
} else
Print("Failed to apply 'my_template.tpl', error code ",GetLastError());
} else {
Print("File 'my_template.tpl' not found in "
+TerminalInfoString(TERMINAL_PATH)+"\\MQL5\\Files");
}
打开指定的货币对,周期,设置模板 注意:ChartRedraw 通常更改物件属性之后使用该函数。
void OnStart() {
long chartOpenID=ChartOpen("GBPUSD",PERIOD_H4);
Print("打开图标的id"+ chartOpenID);
if(FileIsExist("my_template.tpl")) {
Print("The file my_template.tpl found in \Files'");
if(ChartApplyTemplate(chartOpenID,"\\Files\\my_template.tpl")) {
Print("The template 'my_template.tpl' applied successfully");
ChartRedraw();
} else
Print("Failed to apply 'my_template.tpl', error code ",GetLastError());
} else {
Print("File 'my_template.tpl' not found in "
+TerminalInfoString(TERMINAL_PATH)+"\\MQL5\\Files");
}
}
遍历图标窗口id
void OnStart() {
long currChart,prevChart=ChartFirst();
int i=0,limit=100;
Print("ChartFirst =",ChartSymbol(prevChart)," ID =",prevChart);
while(i<limit) {
currChart=ChartNext(prevChart);
if(currChart<0) {
break;
}
Print(i,ChartSymbol(currChart)," ID =",currChart);
prevChart=currChart;
i++;
}
}
运行效果:
把指定的图表关闭
long fistId=ChartFirst();
for(int i=0; i<100; i++) {
if(ChartSymbol(fistId)=="GBPUSD") {
ChartClose(fistId);
}
if(fistId<0) {
break;
}
long nextId= ChartNext(fistId);
fistId=nextId;
}
|