support 发表于 2022-12-2 12:28:05

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

#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, Low, Red);

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

   CreateText("text", Time, High, foo);
   */

   // CreateLine("line", High, Red);

   return 0;
}

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

   ObjectDelete(objectName);

   // Time: left of rect.   startValue: top of rect.   Time: right of rect.    endValue: bottom of rect;
   ObjectCreate(objectName, OBJ_RECTANGLE, 0, Time, startValue, Time, 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;
}

木兮 发表于 2023-11-7 11:09:41

:o
页: [1]
查看完整版本: 量化交易之MQL4篇 - MT4盘面上添加线、矩形、文本