指标杂项问题 - 页 11

 
你能看到我在这个评论#99 中的示例代码吗?
 

哦,好的,这段代码。

ObjectCreate()也需要图表的ID。

bool  ObjectCreate(
   long         chart_id,      // chart identifier
   string       name,          // object name
   ENUM_OBJECT  type,          // object type
   sub_window   nwin,          // window index
   datetime     time1,         // time of the first anchor point
   double       price1,        // price of the first anchor point
   ...
   datetime     timeN=0,       // time of the N-th anchor point
   double       priceN=0,      // price of the N-th anchor point
   ...
   datetime     time30=0,      // time of the 30th anchor point
   double       price30=0      // price of the 30th anchor point
   );

作为第一个参数。

int OnInit()
  {
   Print("Outside");

   ObjectCreate("Object Outside",OBJ_LABEL,0,0,0);
   ObjectSetInteger(0,"Object Outside",OBJPROP_XDISTANCE,20);
   ObjectSetInteger(0,"Object Outside",OBJPROP_YDISTANCE,20);
   ObjectSetString(0,"Object Outside",OBJPROP_TEXT,"Outside");

   if(DayOfWeek()==5)
     {
      Print("Inside");

      ObjectCreate("Object Inside",OBJ_LABEL,0,0,0);
      ObjectSetInteger(0,"Object Inside",OBJPROP_XDISTANCE,20);
      ObjectSetInteger(0,"Object Inside",OBJPROP_YDISTANCE,40);
      ObjectSetString(0,"Object Inside",OBJPROP_TEXT,"Inside");
     }
  }

但是你从objectname开始。

你也可以指定一个基角/锚点。

请看:https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_label

//+------------------------------------------------------------------+
//| Create a text label                                              |
//+------------------------------------------------------------------+
bool LabelCreate(const long              chart_ID=0,               // chart's ID
                 const string            name="Label",             // label name
                 const int               sub_window=0,             // subwindow index
                 const int               x=0,                      // X coordinate
                 const int               y=0,                      // Y coordinate
                 const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // chart corner for anchoring
                 const string            text="Label",             // text
                 const string            font="Arial",             // font
                 const int               font_size=10,             // font size
                 const color             clr=clrRed,               // color
                 const double            angle=0.0,                // text slope
                 const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type
                 const bool              back=false,               // in the background
                 const bool              selection=false,          // highlight to move
                 const bool              hidden=true,              // hidden in the object list
                 const long              z_order=0)                // priority for mouse click
  {
//--- reset the error value
   ResetLastError();
//--- create a text label
   if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))
     {
      Print(__FUNCTION__,
            ": failed to create text label! Error code = ",GetLastError());
      return(false);
     }
//--- set label coordinates
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set the chart's corner, relative to which point coordinates are defined
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set the text
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set text font
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font size
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set the slope angle of the text
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- set anchor type
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- set color
   ObjectSetInteger(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 mouse
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------+

Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL
  • www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL - Reference on algorithmic/automated trading language for MetaTrader 5
 

我只是担心我无法解释我的问题,我想问你有没有试过?然后你就可以知道我的代码有什么问题了。

我只是这样尝试 - 1.我把我的例子文件添加到图表上,然后关闭MT4。2.打开MT4 - 然后我没有看到我的内部标签对象

这就是我试图找到解决我的问题的方法。


也许我周一就能确定了。

(当我认为这很容易的时候,我花了很多时间去做那些简单的事情--当我认为这很难的时候,我却很容易就做到了......--几乎所有我想做的事情,我都会先尝试阅读文档......)

 

我试了一下,有两个对象显示。

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
      Print("Outside");

   ObjectCreate(0,"Object Outside",OBJ_LABEL,0,0,0);
   ObjectSetInteger(0,"Object Outside",OBJPROP_XDISTANCE,20);
   ObjectSetInteger(0,"Object Outside",OBJPROP_YDISTANCE,20);
   ObjectSetString(0,"Object Outside",OBJPROP_TEXT,"Outside");

   if(DayOfWeek()==5)
     {
      Print("Inside");

      ObjectCreate(0,"Object Inside",OBJ_LABEL,0,0,0);
      ObjectSetInteger(0,"Object Inside",OBJPROP_XDISTANCE,20);
      ObjectSetInteger(0,"Object Inside",OBJPROP_YDISTANCE,40);
      ObjectSetString(0,"Object Inside",OBJPROP_TEXT,"Inside");
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+


 

很好!

请看我的屏幕截图。

有一个问题

非常感谢你的时间,马可先生。

 

我不介意那部分代码在指标中给我带来不同的结果。 : /
我在我的指标文件中尝试了这部分代码。

(我决定在指标文件中写一些代码,但不在我的贸易面板 文件中。)


第二次编辑

我已经使用了你的方法--现在它的工作没有任何问题,希望它能发挥作用。

非常感谢,马可先生。


#Not Monday - 关闭
 

#刷新 - 开放

一旦我解决了这个问题,我的指标在我的主MT4平台上运行良好,但我使用第二MT4平台,当我启动MT4平台时,我的指标需要刷新。
我不知道这个问题是怎么来的......我想问的就是这个问题。

问: 请问谁能让我了解一下这种奇怪的情况?

谢谢。

 

你是说你见证了两个平台之间的不同行为?

它们是同一个版本吗?

 
Marco vd Heijden:

你是说你见证了两个平台之间的不同行为?

它们是同一个版本吗?

是的,绝对不同的行为...

还有,这两个平台都是1065版本

 

也许我找到了那些奇怪问题的来源......

负载模板的秘密是什么?
有一个神秘的东西,正在摧毁我......这真的真的让我很生气......--我已经为我的EA和指标做了大量的工作,我从来没有花很多时间,就像我花了一些小问题......

如何找到?很简单!

在我决定不把一些脚本放在我的EA文件中之后--然后我不断地面临一些小问题,我无法在SEO中找到解决方案。(实际上,有时我很容易在SEO中找到解决我的巨大EA问题的方法--但这是小问题。)

---

我把这个简单的代码放在我的例子指标文件中。

int OnInit()
{
  Print( "This Year", Year() );
  return(INIT_SUCCEEDED);
}

当我试图将这个例子文件加载到我的图表上时。它不能正常工作,直到我改变时间框架。
( 可能我今天已经很累了 )
(我也知道如果我把这段代码放在OnCalculate(...)中就可以解决这个问题 - 但我只需要把这段代码放在OnInit()中)

求你了,我只是需要更清楚地解释这个问题。我真的需要它,因为我的一些指标也有同样的不相关问题。(如果我把这个放在我的EA文件里,它就会正常工作)

先谢谢你了。
祝你周末愉快。