void OnStart() {
string vlineObject = "vlineObject";
string hlineObject = "hlineObject";
string trendObject = "trendObject";
string trendbyangleObject = "trendbyangleObject";
string fiboObject = "fiboObject";
string textObject = "textObject";
string labelObject = "labelObject";
// 创建 垂直线 对象, 参数(sub_window): 0代表在主图上创建对象, 1代表在附图上创建对象
ObjectCreate(vlineObject, OBJ_VLINE, 0, Time[2], Open[0]);
// 创建 水平线 对象, 并获得所对应的价格和颜色
ObjectCreate(hlineObject, OBJ_HLINE, 0, Time[1], Open[1]);
ObjectSet(hlineObject, OBJPROP_COLOR, clrDarkViolet);
ObjectSet(hlineObject, OBJPROP_WIDTH, 3);
double hlinePrice = ObjectGet(hlineObject, OBJPROP_PRICE1);
color colorValue = ObjectGet(hlineObject, OBJPROP_COLOR);
Alert("hlinePrice: " + hlinePrice);
Alert("colorValue: " + colorValue);
// 创建 趋势线 对象
ObjectCreate(trendObject, OBJ_TREND, 0, Time[9], Low[9], Time[0], Low[0]);
ObjectSet(trendObject, OBJPROP_COLOR, clrWhite);
// 后两个参数: (OBJPROP_RAY, false)代表从点(Time[9], Low[9])开始到点(Time[0], Low[0])的一条线段, (OBJPROP_RAY, true)代表从点(Time[9], Low[9])开始穿过点(Time[0], Low[0])的一条射线
ObjectSet(trendObject, OBJPROP_RAY, false);
double trendObjectPrice = ObjectGetValueByShift(trendObject, 0);
Alert("0号k线上趋势线的值: " + trendObjectPrice);
// 创建 固定角度的趋势线 对象
ObjectCreate(trendbyangleObject, OBJ_TRENDBYANGLE, 0, Time[10], Open[10], Time[0], Low[0]);
ObjectSet(trendbyangleObject, OBJPROP_ANGLE, 30);
ObjectSet(trendbyangleObject, OBJPROP_COLOR, clrYellow);
ObjectSet(trendbyangleObject, OBJPROP_RAY, false);
int angle = ObjectGet(trendbyangleObject, OBJPROP_ANGLE);
Alert("angle: " + angle);
// 创建 斐波那契 对象
ObjectCreate(fiboObject, OBJ_FIBO, 0, Time[9], High[9], Time[0], Low[0]);
// 创建 text 对象
ObjectCreate(textObject, OBJ_TEXT, 0, Time[1], High[1]);
ObjectSetText(textObject, "谢谢", 10, "宋体", Yellow);
// 创建 label 对象
ObjectCreate(labelObject, OBJ_LABEL, 0, 10, 10);
ObjectSet(labelObject, OBJPROP_XDISTANCE, 150);
ObjectSet(labelObject, OBJPROP_YDISTANCE, 15);
ObjectSet(labelObject, OBJPROP_CORNER, CORNER_LEFT_UPPER);
ObjectSetText(labelObject, "你好", 10, "宋体", Yellow);
delectAllObjects(); // 功能等同于:ObjectsDeleteAll();
}
void delectAllObjects() {
int total = ObjectsTotal();
for(int i = total; i>=0; i--) {
string objectName=ObjectName(i);
Print(IntegerToString(i) + " |" + objectName);
ObjectDelete(objectName);
}
return;
}
标签:函数,hlineObject,Low,ObjectSet,Time,量化,MQL4,string,OBJPROP
From: https://blog.51cto.com/u_9527606/6173843