boolObjectCreate(
long chart_id, // chart identifierstring name, // object nameENUM_OBJECT type, // object type
sub_window nwin, // window indexdatetime time1, // time of the first anchor pointdouble price1, // price of the first anchor point
...
datetime timeN=0, // time of the N-th anchor pointdouble priceN=0, // price of the N-th anchor point
...
datetime time30=0, // time of the 30th anchor pointdouble price30=0// price of the 30th anchor point
);
//+------------------------------------------------------------------+//| Create a text label |//+------------------------------------------------------------------+bool LabelCreate(constlong chart_ID=0, // chart's IDconststring name="Label", // label nameconstint sub_window=0, // subwindow indexconstint x=0, // X coordinateconstint y=0, // Y coordinateconstENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoringconststring text="Label", // textconststring font="Arial", // fontconstint font_size=10, // font sizeconstcolor clr=clrRed, // colorconstdouble angle=0.0, // text slopeconstENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor typeconstbool back=false, // in the backgroundconstbool selection=false, // highlight to moveconstbool hidden=true, // hidden in the object listconstlong z_order=0) // priority for mouse click
{
//--- reset the error valueResetLastError();
//--- create a text labelif(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))
{
Print(__FUNCTION__,
": failed to create text label! Error code = ",GetLastError());
return(false);
}
//--- set label coordinatesObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set the chart's corner, relative to which point coordinates are definedObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set the textObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set text fontObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font sizeObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set the slope angle of the textObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- set anchor typeObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- set colorObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- display in the foreground (false) or background (true)ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the label by mouseObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object listObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chartObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful executionreturn(true);
}
//+------------------------------------------------------------------+
Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL - Reference on algorithmic/automated trading language for MetaTrader 5
哦,好的,这段代码。
ObjectCreate()也需要图表的ID。
作为第一个参数。
但是你从objectname开始。
你也可以指定一个基角/锚点。
请看:https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_label
我只是担心我无法解释我的问题,我想问你有没有试过?然后你就可以知道我的代码有什么问题了。
我只是这样尝试 - 1.我把我的例子文件添加到图表上,然后关闭MT4。2.打开MT4 - 然后我没有看到我的内部标签对象。
这就是我试图找到解决我的问题的方法。
也许我周一就能确定了。
(当我认为这很容易的时候,我花了很多时间去做那些简单的事情--当我认为这很难的时候,我却很容易就做到了......--几乎所有我想做的事情,我都会先尝试阅读文档......)
我试了一下,有两个对象显示。
很好!
请看我的屏幕截图。
非常感谢你的时间,马可先生。
我不介意那部分代码在指标中给我带来不同的结果。 : /
我在我的指标文件中尝试了这部分代码。
(我决定在指标文件中写一些代码,但不在我的贸易面板 文件中。)
第二次编辑
我已经使用了你的方法--现在它的工作没有任何问题,希望它能发挥作用。
非常感谢,马可先生。
#Not Monday - 关闭
#刷新 - 开放
一旦我解决了这个问题,我的指标在我的主MT4平台上运行良好,但我使用第二MT4平台,当我启动MT4平台时,我的指标需要刷新。
我不知道这个问题是怎么来的......我想问的就是这个问题。
问: 请问谁能让我了解一下这种奇怪的情况?
谢谢。
你是说你见证了两个平台之间的不同行为?
它们是同一个版本吗?
你是说你见证了两个平台之间的不同行为?
它们是同一个版本吗?
是的,绝对不同的行为...
还有,这两个平台都是1065版本
也许我找到了那些奇怪问题的来源......
负载模板的秘密是什么?
有一个神秘的东西,正在摧毁我......这真的真的让我很生气......--我已经为我的EA和指标做了大量的工作,我从来没有花很多时间,就像我花了一些小问题......
如何找到?很简单!
在我决定不把一些脚本放在我的EA文件中之后--然后我不断地面临一些小问题,我无法在SEO中找到解决方案。(实际上,有时我很容易在SEO中找到解决我的巨大EA问题的方法--但这是小问题。)
---
我把这个简单的代码放在我的例子指标文件中。
当我试图将这个例子文件加载到我的图表上时。它不能正常工作,直到我改变时间框架。
( 可能我今天已经很累了 )
(我也知道如果我把这段代码放在OnCalculate(...)中就可以解决这个问题 - 但我只需要把这段代码放在OnInit()中)
求你了,我只是需要更清楚地解释这个问题。我真的需要它,因为我的一些指标也有同样的不相关问题。(如果我把这个放在我的EA文件里,它就会正常工作)
先谢谢你了。
祝你周末愉快。