OBJ_VLINE - página 3

 

Muchas gracias Marco por la ayuda, por alguna razón está funcionando

He configurado el tiempo en el formato D', a continuación, muestra que la información como una alerta, que se puede ver coincide con los tiempos de flecha sin embargo

la línea V se sigue creando en la vela actual .. ver captura de pantalla


Este es el código que he utilizado

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


 
Este es un tema relacionado: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:
Aquí hay un tema relacionado:https://www.mql5.com/en/forum/233876

Ya tengo las v-líneas en el gráfico desde que conocí el desplazamiento , en el tema en el enlace dibujaron las v-líneas usando el desplazamiento

En mis posts anteriores mencioné que perdía las v-lines que creaba cuando el VPS se reiniciaba o durante los fines de semana o a veces al reiniciar MT4 , por lo que guardaba las fechas de las v-lines para intentar volver a crearlas más tarde si se perdían.

Parece que MT4 no tiene la capacidad de crear v-lines a partir de fechas de texto o nadie ha descubierto cómo se hace todavía

 
Alpha Beta:

En mis posts anteriores he mencionado que pierdo las líneas v que he creado cuando el VPS se reinicia o durante los fines de semana o a veces cuando se reinicia MT4 , por lo que guardo las fechas de las líneas v para intentar volver a crearlas más tarde si se han perdido.

Si ha guardado las fechas como :

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

Aquí para recrear las v-lines no necesitas dividir los dígitos de los segundos delTimeExit_SymSymbol ..el trabajo lo hace el propioObjectCreate(),porque no tiene en cuenta los segundos.

Puedes simplificar tus códigos de la siguiente manera:

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

Bueno, rápidamente probé un script y eso ciertamente dibuja la línea hacia el futuro.

//+------------------------------------------------------------------+
//|                                                        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:

Bueno, rápidamente probé un script y eso ciertamente dibuja la línea hacia el futuro.

Estimado Marco,

Estás utilizando el desplazamiento correspondiente a la barra actual, que es el mismo método que he utilizado para crear las V-Lines para mis gráficos , sin embargo el problema es crear la V-Line sin conocer el desplazamiento y sin hacer referencia a la hora/barra actual, el problema es crear las V-Lines conociendo la hora/fecha SOLO

Ya que pierdo las v-lines a veces cuando el VPS se reinicia y otras veces durante el fin de semana, es por eso que la única opción que encontré es guardar la hora/fecha de las líneas en el gráfico y luego tratar de volver a crearlas, guardar el turno no ayuda mucho ya que las barras progresan y además están las barras del fin de semana .

según el MT4 (https://www.mql5.com/en/docs/objects/objectcreate) la V-Line se puede crear usando solo la hora/fecha .. me gustaría ver como se hace ya que no lo he visto en ningún sitio y me he cansado sin suerte

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...
 

Por fin he descubierto cómo se hace

aquí está el código por si alguien quiere dibujar una línea V usando sólo la hora/fecha

         // 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:

Finalmente he descubierto cómo se hace

Este es el código por si alguien quiere dibujar una línea V usando sólo la hora/fecha

  1. No es así como se hace. Todo lo que hiciste fue
    1. Toma una fecha y conviértela en una estructura.
    2. Tome la estructura y convertirlo en una cadena (sin los segundos.)
    3. Tome la cadena y convertirlo de nuevo a la fecha original (sin los segundos.)
    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. Si todo lo que querías era quitar los segundos, así es como se hace:
    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. No es así como se hace. Todo lo que hiciste fue
    1. Toma una fecha y conviértela en una estructura.
    2. Tome la estructura y conviértala en una cadena (sin los segundos).
    3. Toma la cadena y conviértela de nuevo en la fecha original (sin los segundos).

  2. Si todo lo que querías era eliminar los segundos, así es como se hace:

Si miras mis posts anteriores verás que intenté quitar los segundos, pero no funcionó, sin embargo después de la conversión el código funcionó no estoy seguro de lo que estaba mal,

Me gusta su versión del código es simple, elegante y funciona bien, gracias

 
Es la primera vez que utilizo artículos gráficos en un puntero. Necesitaría dibujar una línea vertical ordinaria en el tiempo "22:00", ¿podría por favor dirigirme a una respuesta?
Razón de la queja: