0
点赞
收藏
分享

微信扫一扫

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

zhaoxj0217 2023-03-02 阅读 24


#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;

}

举报

相关推荐

0 条评论