OBJ_VLINE - pagina 3

 

Grazie mille Marco per l'aiuto, per qualche motivo funziona

Ho configurato il tempo nel formato D', poi ho visualizzato questa informazione come un avviso, che si può vedere corrisponde ai tempi della freccia però

la V-Line è ancora creata sulla candela corrente .. vedi schermata


Questo è il codice che ho usato

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


 
Ecco un argomento correlato: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:
Ecco un argomento correlato:https://www.mql5.com/en/forum/233876

Io ho già delle linee di v sul grafico da quando conosco lo spostamento, nell'argomento del link hanno disegnato le linee di v usando lo spostamento

Nei miei post precedenti ho accennato al fatto che perdo le v-lines che ho creato quando il VPS si riavvia o durante i fine settimana o a volte quando si riavvia MT4, quindi salvo le date delle v-lines nel tentativo di ricrearle in seguito se sono state perse.

Sembra che MT4 non abbia la capacità di creare linee v da date di testo o nessuno ha ancora capito come si fa

 
Alpha Beta:

Nei miei post precedenti ho menzionato che perdo le linee v che ho creato quando il VPS si riavvia o durante i fine settimana o a volte quando si riavvia MT4, quindi salvo le date delle linee v nel tentativo di ricrearle in seguito se sono state perse.

Se hai salvato le date come :

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

Qui per ricreare le linee v non è necessario dividere le cifre dei secondi daTimeExit_SymSymbol...il lavoro è fatto daObjectCreate() stesso, perché non prende in considerazione i secondi.

Potete semplificare i vostri codici con:

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

Beh, ho provato rapidamente uno script e questo certamente traccia la linea del 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:

Beh, ho provato rapidamente uno script e questo certamente traccia la linea del futuro.

Caro Marco,

Stai usando lo spostamento relativo alla barra corrente, che è lo stesso metodo che ho usato per creare le V-Line per i miei grafici, tuttavia il problema è creare la V-Line senza conoscere lo spostamento e senza fare riferimento all'ora/barra corrente, il problema è creare le V-Line conoscendo SOLO l'ora/data

Dato che perdo le V-Lines a volte quando il VPS si riavvia e altre volte durante il fine settimana, ecco perché l'unica opzione che ho trovato è quella di salvare l'ora/data delle linee sul grafico e poi provare a ricrearle di nuovo, salvando lo spostamento non aiuta molto con l'avanzamento delle barre e inoltre ci sono le barre del fine settimana.

secondo MT4 (https://www.mql5.com/en/docs/objects/objectcreate) la V-Line può essere creata usando solo la data/ora... vorrei vedere come si fa dato che non l'ho visto da nessuna parte e mi sono stancato senza fortuna

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

Finalmente ho capito come si fa

ecco il codice se qualcuno volesse mai disegnare la V-Line usando solo l'ora e la data

         // 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 ho capito come si fa

Ecco il codice se qualcuno volesse mai disegnare V-Line usando solo il tempo/data

  1. Non è così che si fa. Tutto quello che hai fatto è stato
    1. Prendete un datetime e convertitelo in una struct.
    2. Prendete la struct e convertitela in una stringa (senza i secondi).
    3. Prendete la stringa e convertitela di nuovo nel datetime originale (senza i secondi).
    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. Se tutto quello che volevi era rimuovere i secondi, ecco come si fa:
    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. Non è così che si fa. Tutto quello che hai fatto è stato
    1. Prendete un datetime e convertitelo nella struct.
    2. Prendete la struct e convertitela in una stringa (senza i secondi).
    3. Prendete la stringa e convertitela di nuovo nel datetime originale (senza i secondi).

  2. Se tutto quello che volevi era rimuovere i secondi, ecco come si fa:

Se hai guardato i miei post precedenti vedrai che ho provato a rimuovere i secondi, ma non ha funzionato, tuttavia dopo la conversione il codice ha funzionato, non so cosa fosse sbagliato,

Mi piace la tua versione del codice, è semplice, elegante e funziona bene, grazie

 
È la prima volta che utilizzo articoli grafici in un puntatore. Avrei bisogno di disegnare una linea verticale ordinariamente nel frattempo "22:00", potreste per favore indirizzarmi verso una risposta?
Motivazione: