but is possible draw diagonal line ?

 

 hi guys i have creted a diagonal line  but this line must  pass in  iterception of  ass X and Ass y  like fugure

now i trace it with tool but i want  the daw line  directly by my code  i sue this  code

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.06"
#property strict

input string crossSymbolY = "EURJPY+"; // Cross valutario da visualizzare Asse Y
input string crossSymbolX = "USDJPY+"; // Cross valutario da visualizzare Asse X
input int numLabels = 10; // Numero di etichette verticali

int OnInit()
{
   // Subito al caricamento dell'EA, disegna la "metro line"
   DrawMetroStyleLine();
   return(INIT_SUCCEEDED);
}

void OnTick()
{
   // Funzione OnTick vuota per possibili aggiornamenti
}

void DrawMetroStyleLine()
{
   string baseName = "MetroLine_";
   int window = 0;
   double priceMin, priceMax;

   // Ottieni il range di prezzo visibile
   if(!ChartPriceMinMax(0, window, priceMin, priceMax))
   {
      Print("Errore nel calcolo dei limiti del grafico: ", GetLastError());
      return;
   }

   double step = (priceMax - priceMin) / (numLabels - 1);
   double midValue = (priceMax + priceMin) / 2.0;
   string mainLine = "MetroMainLine";
   string verticalAxis = "MetroYAxis";
   string lineZ = "LineZ";  // Nome per la linea Z

   // Crea una linea principale al centro ASSE X
   if(!ObjectCreate(0, mainLine, OBJ_HLINE, window, 0, midValue))
   {
      Print("Errore nella creazione della linea principale: ", GetLastError());
      return;
   }
   ObjectSetInteger(0, mainLine, OBJPROP_COLOR, clrRed);
   ObjectSetInteger(0, mainLine, OBJPROP_WIDTH, 2);
   ObjectSetInteger(0, mainLine, OBJPROP_STYLE, STYLE_SOLID);
   
   // Crea una linea verticale centrata al prezzo medio ASSE Y 
   if(!ObjectCreate(0, verticalAxis, OBJ_VLINE, window, TimeCurrent(), midValue))
   {
      Print("Errore nella creazione della linea verticale: ", GetLastError());
      return;
   }
   // Imposta il colore della linea verticale inizialmente a verde
   ObjectSetInteger(0, verticalAxis, OBJPROP_COLOR, clrRed);
   ObjectSetInteger(0, verticalAxis, OBJPROP_WIDTH, 2);
   ObjectSetInteger(0, verticalAxis, OBJPROP_STYLE, STYLE_SOLID);

   // Recupera i tempi delle barre (ad esempio, le prime 2 barre)
   datetime timeArray[];
   int copied = CopyTime(Symbol(), PERIOD_CURRENT, 0, 2, timeArray);

   if (copied < 2)
   {
      Print("Errore nel recupero dei tempi delle barre: ", GetLastError());
      return;
   }

   // Crea la linea Z che passa per l'incrocio delle linee X e Y
   datetime timeLeftTop = timeArray[1];  // Tempo della prima barra (angolo sinistro alto)
   datetime timeRightBottom = TimeCurrent();  // Tempo dell'angolo destro basso (tempo corrente)

   // Crea la linea Z dal sinistro in alto al destro in basso
   if(!ObjectCreate(0, lineZ, OBJ_TREND, window, timeLeftTop, priceMax, timeRightBottom, priceMin))
   {
      Print("Errore nella creazione della linea Z: ", GetLastError());
      return;
   }
   ObjectSetInteger(0, lineZ, OBJPROP_COLOR, clrRed);
   ObjectSetInteger(0, lineZ, OBJPROP_WIDTH, 2);
   ObjectSetInteger(0, lineZ, OBJPROP_STYLE, STYLE_SOLID);

   // Crea le tacche e le etichette
   for(int i = 0; i < numLabels; i++)
   {
      double priceLevel = priceMax - (step * i);
      string lineName = baseName + IntegerToString(i);
      string textName = "PriceLabel_" + IntegerToString(i);
      
      // Crea una tacca (piccola linea verticale rispetto alla linea principale)
      if(!ObjectCreate(0, lineName, OBJ_TREND, window, TimeCurrent(), priceLevel, TimeCurrent() + 10, priceLevel))
      {
         Print("Errore nella creazione della tacca: ", GetLastError());
         continue;
      }

      // Imposta lo stile della tacca
      ObjectSetInteger(0, lineName, OBJPROP_COLOR, clrLime);
      ObjectSetInteger(0, lineName, OBJPROP_WIDTH, 2);
      ObjectSetInteger(0, lineName, OBJPROP_RAY_RIGHT, false);
      ObjectSetInteger(0, lineName, OBJPROP_RAY_LEFT, false);
      
      // Aggiunge il testo del prezzo accanto alla tacca
      if(!ObjectCreate(0, textName, OBJ_TEXT, window, TimeCurrent() + 12, priceLevel))
      {
         Print("Errore nella creazione dell'etichetta: ", GetLastError());
         continue;
      }
      ObjectSetString(0, textName, OBJPROP_TEXT, StringFormat("%.5f", priceLevel));
      ObjectSetInteger(0, textName, OBJPROP_COLOR, clrGreen);
      ObjectSetInteger(0, textName, OBJPROP_FONTSIZE, 10);
      ObjectSetInteger(0, textName, OBJPROP_ANCHOR, ANCHOR_CENTER);
   }
}


//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   ObjectDelete(0, "MetroMainLine");
   ObjectDelete(0, "MetroYAxis");
   for(int i = 0; i < 20; i++) // Rimuove tutte le tacche ed etichette
   {
      ObjectDelete(0, "MetroLine_" + IntegerToString(i));
      ObjectDelete(0, "PriceLabel_" + IntegerToString(i));
   }
}

//+------------------------------------------------------------------+
//| Funzione per ottenere i limiti di prezzo visibili nel grafico    |
//+------------------------------------------------------------------+
bool ChartPriceMinMax(long chartId, int subWindow, double &priceMin, double &priceMax)
{
   priceMin = ChartGetDouble(chartId, CHART_PRICE_MIN, subWindow);
   priceMax = ChartGetDouble(chartId, CHART_PRICE_MAX, subWindow);
   return (priceMin != 0 && priceMax != 0);
}
but with my code not draw nothing  anyone can help me  ?thanks
 
faustf:

 hi guys i have creted a diagonal line  but this line must  pass in  iterception of  ass X and Ass y  like fugure

now i trace it with tool but i want  the daw line  directly by my code  i sue this  code

but with my code not draw nothing  anyone can help me  ?thanks

Try setting timeArray as a series (a time series) with ArraySetAsSeries().

Overview of Copy functions for obtaining arrays of quotes - Creating application programs - MQL5 Programming for Traders - MetaTrader 5 algorithmic/automatic trading language manual

MQL5 Book: Creating application programs / Timeseries / Overview of Copy functions for obtaining arrays of quotes
MQL5 Book: Creating application programs / Timeseries / Overview of Copy functions for obtaining arrays of quotes
  • www.mql5.com
The MQL5 API contains several functions for reading quote timeseries into arrays. Their names are given in the following table. All functions take...
 
faustf:
… my code not draw nothing

ChartRedraw function calls a forced redrawing of a specified chart. Usually it is used after changing the object properties.

int OnInit()
{
   //…
   ChartRedraw();
   return(INIT_SUCCEEDED);
}


Replaced the previous approach with iTime() for simplicity.

//datetime timeLeftTop = timeArray[1];  // Tempo della prima barra (angolo sinistro alto)
datetime timeLeftTop = iTime(Symbol(),Period(),1); 


To delete the "LineZ" object.

void OnDeinit(const int reason)
{
   //…
   ObjectDelete(0, "LineZ");
}


Also replace those trend lines and labels with OBJ_ARROW_RIGHT_PRICE.