找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
首页论坛EAHub 外汇论坛
查看: 11|回复: 0

量化交易之MQL4篇 - MT4盘面上添加线、矩形、文本

[复制链接]

4万

主题

54

回帖

4万

积分

管理员

积分
45954
发表于 2026-8-23 00:48:00 | 显示全部楼层 |阅读模式
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

int start() {

   //CreateColorRect("rect", High[2], Low[0], Red);

   /*
   string foo = DoubleToString(Bid, Digits);
   foo += foo;

   CreateText("text", Time[4], High[5], foo);
   */

   // CreateLine("line", High[0], Red);

   return 0;
}

void CreateColorRect(string objectName, double startValue, double endValue, color colorValue) {

   ObjectDelete(objectName);

   // Time[3]: left of rect.   startValue: top of rect.   Time[0]: right of rect.    endValue: bottom of rect;
   ObjectCreate(objectName, OBJ_RECTANGLE, 0, Time[3], startValue, Time[0], endValue);
   ObjectSet(objectName, OBJPROP_COLOR, colorValue);
   ObjectSet(objectName, OBJPROP_WIDTH, 1);
   ObjectSet(objectName, OBJPROP_STYLE, 0);
   // false: rect中间是透明的. true: rect中间不是透明的
   ObjectSet(objectName, OBJPROP_BACK, false);

}

void CreateText(string objectName, datetime timeValue, double dataValue, string stringValue) {

   ObjectDelete(objectName);
   // timeValue: middle of text is equal to middle of timeValue. dataValue: top of text is equal to top of dataValue.
   ObjectCreate(objectName, OBJ_TEXT, 0, timeValue, dataValue);
   ObjectSetText(objectName, stringValue, 10, "Arial", Yellow);

}

void CreateLine(string objectName, double data, color colorValue) {

   ObjectDelete(objectName);
   // data: top of line
   ObjectCreate(objectName, OBJ_HLINE, 0, 0, data);
   ObjectSet(objectName, OBJPROP_COLOR, colorValue);

}

int deinit(){

   ObjectsDeleteAll();

   return 0;
}
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|EAHub外汇论坛

GMT+8, 2026-10-12 09:40 , Processed in 0.106000 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表