图标操作示例

要先打开一个窗口。

模板引用


//--- 应用模板示例,位于\MQL5\Files
// 如果手动保存的模板是默认放   MQL5\Profiles\Templates
   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);


//--- 应用模板示例,位于\MQL5\Files
// 如果手动保存的模板是默认放   MQL5\Profiles\Templates
   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() {


//--- 用于图表 ID的变量
   long currChart,prevChart=ChartFirst();
   int i=0,limit=100;
   Print("ChartFirst =",ChartSymbol(prevChart)," ID =",prevChart);
   while(i<limit) { // 不允许超过100个打开的窗口
      currChart=ChartNext(prevChart); // 通过使用之前图表ID获得新图表ID
      if(currChart<0) {
         break;          // 到达了图表列表末端
      }
      Print(i,ChartSymbol(currChart)," ID =",currChart);
      prevChart=currChart;// 为ChartNext()保存当前图表ID
      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;
   }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值