OBJ_VLINE - 页 3

 

非常感谢Marco的帮助,由于某些原因,它在工作。

我配置了D'格式的时间,然后将该信息显示为警报,你可以看到它与箭头时间相匹配。

V型线仍然是在当前的蜡烛上创建的...见屏幕截图


这是我使用的代码

ObjectDelete(0,"v_line1");
         ObjectDelete(0,"v_line2");
        
        
         datetime TimeExit_SymSymbol = (datetime) ObjectGetInteger(0, Exit_SymSymbol, OBJPROP_TIME1);
         MqlDateTime str1;
         TimeToStruct(TimeExit_SymSymbol,str1);
         int Year = str1.year;
         int Month = str1.mon;
         int Day = str1.day;
         int Hour = str1.hour;
         int Minutes = str1.min;
         int Seconds = str1.sec;
        
         string V1DateString= "D'"+str1.year+"."+str1.mon+"."+str1.day+" "+ str1.hour+":" + str1.min+"'";//+":"+str1.sec+"'";
         
         ObjectCreate(0, "v_line1", OBJ_VLINE, 0, V1DateString, High[0]);
         ObjectCreate(0, "v_line2", OBJ_VLINE, 0, StringToTime(V1DateString), High[0]);
         Alert(V1DateString);


 
这里有一个相关的话题:https://www.mql5.com/en/forum/233876
Vline 50 bars after the current time/bar
Vline 50 bars after the current time/bar
  • 2018.03.31
  • www.mql5.com
Hi there, I come to you to ask you : How can i draw a VLINE on the 50th (or Xth) bar in the future...
 
Marco vd Heijden:
这里有一个相关的主题:https://www.mql5.com/en/forum/233876

我已经在图表上有了v-line,因为我知道移位,在链接的主题中,他们使用移位画了v-line。

在我之前的文章中,我提到当VPS重启或在周末或有时重启MT4时,我失去了我创建的v-line,所以我保存了v-line的日期,试图在他们丢失后重新创建它们。

似乎MT4没有能力从文本日期创建v-line,或者还没有人知道如何做。

 
Alpha Beta:

在我之前的文章中,我提到当VPS重启或在周末或有时重启MT4时,我丢失了我创建的v-line,所以我保存了v-line的日期,试图在丢失后重新创建它们。

如果您将日期保存为:

datetime TimeExit_SymSymbol = (datetime) ObjectGetInteger(0, Exit_SymSymbol, OBJPROP_TIME1);

在这里重新创建v-line,你不需要从TimeExit_SymSymbol 中拆分秒数,这项工作由ObjectCreate() 本身完成,因为它没有考虑到秒数。

你可以通过以下方式简化你的代码。

ObjectDelete(0,"v_line1");
ObjectCreate(0, "v_line1", OBJ_VLINE, 0, TimeExit_SymSymbol, 0);
 

好吧,我很快就试了一个脚本,这当然是把线划到了未来。

//+------------------------------------------------------------------+
//|                                                        Vline.mq4 |
//|        Copyright 2019, MarcovdHeijden, MetaQuotes Software Corp. |
//|                   https://www.mql5.com/en/users/thecreator1/news |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MarcovdHeijden, MetaQuotes Software Corp."
#property link      "https://www.mql5.com/en/users/thecreator1/news"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- assemble time parameter
   datetime time=Time[0]+50*PeriodSeconds();
//--- create v line
   VLineCreate(0,"V-Line-"+TimeToString(time,TIME_DATE),0,time);
//---   
  }
//+------------------------------------------------------------------+ 
//| Create the vertical line                                         | 
//+------------------------------------------------------------------+ 
bool VLineCreate(const long            chart_ID=0,// chart's ID 
                 const string          name="VLine",      // line name 
                 const int             sub_window=0,      // subwindow index 
                 datetime              _time=0,// line time 
                 const color           clr=clrRed,        // line color 
                 const ENUM_LINE_STYLE style=STYLE_SOLID, // line style 
                 const int             width=1,           // line width 
                 const bool            back=false,        // in the background 
                 const bool            selection=false,// highlight to move 
                 const bool            ray=true,          // line's continuation down 
                 const bool            hidden=true,       // hidden in the object list 
                 const long            z_order=0)         // priority for mouse click 
  {
//--- if the line time is not set, draw it via the last bar 
   if(!_time)
      _time=TimeCurrent();
//--- reset the error value 
   ResetLastError();
//--- create a vertical line 
   if(!ObjectCreate(chart_ID,name,OBJ_VLINE,sub_window,_time,0))
     {
      Print(__FUNCTION__,
            ": failed to create a vertical line! Error code = ",GetLastError());
      return(false);
     }
//--- set line color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set line display style 
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set line width 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- 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 line by mouse 
//--- when creating a graphical object using ObjectCreate function, the object cannot be 
//--- highlighted and moved by default. Inside this method, selection parameter 
//--- is true by default making it possible to highlight and move the object 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- enable (true) or disable (false) the mode of displaying the line in the chart subwindows 
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY,ray);
//--- 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);
  }
//+------------------------------------------------------------------+ 
//| Move the vertical line                                           | 
//+------------------------------------------------------------------+ 
bool VLineMove(const long   chart_ID=0,// chart's ID 
               const string name="VLine",// line name 
               datetime     _time=0) // line time 
  {
//--- if line time is not set, move the line to the last bar 
   if(!_time)
      _time=TimeCurrent();
//--- reset the error value 
   ResetLastError();
//--- move the vertical line 
   if(!ObjectMove(chart_ID,name,0,_time,0))
     {
      Print(__FUNCTION__,
            ": failed to move the vertical line! Error code = ",GetLastError());
      return(false);
     }
//--- successful execution 
   return(true);
  }
//+------------------------------------------------------------------+ 
//| Delete the vertical line                                         | 
//+------------------------------------------------------------------+ 
bool VLineDelete(const long   chart_ID=0,// chart's ID 
                 const string name="VLine") // line name 
  {
//--- reset the error value 
   ResetLastError();
//--- delete the vertical line 
   if(!ObjectDelete(chart_ID,name))
     {
      Print(__FUNCTION__,
            ": failed to delete the vertical line! Error code = ",GetLastError());
      return(false);
     }
//--- successful execution 
   return(true);
  }
//+------------------------------------------------------------------+ 
 
Marco vd Heijden:

好吧,我很快就试了一个脚本,这无疑是把线划到了未来。

亲爱的Marco。

你使用的是与当前条形图有关的移位,这与我为我的图表创建V型线的方法相同,然而问题是在不知道移位和不参考当前时间/条形图 的情况下创建V型线,问题是在知道时间/日期的情况下创建V型线ONLY

由于我有时会在VPS重启时丢失V型线,有时会在周末丢失,这就是为什么我发现唯一的选择是在图表上保存线的时间/日期,然后再尝试重新创建它们,随着条形图的发展,保存移位不会有什么帮助,而且还有周末的条形图。

根据MT4(https://www.mql5.com/en/docs/objects/objectcreate),V型线可以只使用时间/日期来创建。我想看看它是如何完成的,因为我没有在任何地方看到它,我累了,没有任何运气。

Documentation on MQL5: Object Functions / ObjectCreate
Documentation on MQL5: Object Functions / ObjectCreate
  • www.mql5.com
The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow. During creation up to 30 coordinates can be specified. The function returns true if the command has been successfully added to the queue of the specified chart, or false otherwise. If an object has already been created, an...
 

我终于知道它是怎么做的了

如果有人想只用时间/日期来画V形线,这里有代码

         // InputDateTime= is the time you want to use to draw the VLine
       
         datetime TimeVLineFile = (datetime) ObjectGetInteger(0, InputDateTime, OBJPROP_TIME1);
         MqlDateTime str1;
         TimeToStruct(TimeVLineFile ,str1);
         int Year = str1.year;
         int Month = str1.mon;
         int Day = str1.day;
         int Hour = str1.hour;
         int Minutes = str1.min;
         int Seconds = str1.sec;
        
      
   
         string VLineDateFormat= str1.year+"."+str1.mon+"."+str1.day+" "+ str1.hour+":" + str1.min; 
         
         
         ObjectCreate(0, "L3", OBJ_VLINE, 0, StringToTime(VLineDateFormat), High[0]);
 
Alpha Beta:

我终于知道它是怎么做的了

如果有人想只用时间/日期来画V型线,这里的代码如下

  1. 这不是它的做法。你所做的只是
    1. 取一个日期时间 并将其转换为结构
    2. 取出该结构 并将其转换为字符串(不含。)
    3. 取出字符串并将其转换为原始日期时间(不含秒)。
    datetime TimeVLineFile = (datetime) ObjectGetInteger(0, InputDateTime, OBJPROP_TIME1);
    MqlDateTime str1;
    TimeToStruct(TimeVLineFile ,str1);
    int Year = str1.year;
    int Month = str1.mon;
    int Day = str1.day;
    int Hour = str1.hour;
    int Minutes = str1.min;
    int Seconds = str1.sec;
    
    string VLineDateFormat= str1.year+"."+str1.mon+"."+str1.day+" "+ str1.hour+":" + str1.min;   
    
    ObjectCreate(0, "L3", OBJ_VLINE, 0, StringToTime(VLineDateFormat), High[0]);

  2. 如果你只想去 秒数,那就是这样做的。
    datetime  TimeVLineFile = (datetime) ObjectGetInteger(0, InputDateTime, OBJPROP_TIME1);
    datetime TimeVLineSansSeconds = TimeVlineFile - TimeVlineFile % 60;
    
    ObjectCreate(0, "L3", OBJ_VLINE, 0, TimeVLineSansSeconds, High[0]);
 
William Roeder:
  1. 这不是它的做法。你所做的只是
    1. 取一个日期时间 并将其转换为结构
    2. 取出该结构 并将其转换为字符串(不含。)
    3. 取出字符串并将其转换为原始日期时间(不含秒。)

  2. 如果你只想去掉秒,这就是你的做法。

如果你看了我以前的帖子,你会发现我累了,去掉了,但是没有用,不过在转换之后,代码还是有效的,不知道哪里出了问题。

我喜欢你这个版本的代码,它简单、优雅,而且运行良好,谢谢

 
这是我第一次在指针中使用图形文章。我需要在 "22:00 "这段时间内画一条垂直线,你能不能指导我找到答案?