Create digonal lines between varios points

 

I'm trying to create a line that follows the following settings to form a triangle:


-starting from the lowest price and linking the inteception between line3 and SQ2#DOWN

-starting from the highest price and linking the inteception between line3 and SQ2#UP


the image illustrate my intention: https://charts.mql5.com/26/292/eurusd-m5-deriv-limited-3.png


//+------------------------------------------------------------------+
//|                                                       EURUSD.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property script_show_inputs

input group           "Tendencia"
input bool Highest=true;
input bool Lowest=false;
input color colorHLINE=Red;
input color colorVLINE=Red;

///////////////////
int Digitos;


double High[];
double Low[];
int HighestCandle;
int LowestCandle;
double Price;
datetime Time;
///////////////////

void DeleteObjects(string name)
{
   ObjectDelete(0,name);
}

void OnDeinit(const int reason)
{
   EventKillTimer();
DeleteObjects("SQ1#DOWN");
DeleteObjects("SQ2#DOWN");
DeleteObjects("SQ3#DOWN");
DeleteObjects("SQ4#DOWN");
DeleteObjects("SQ5#DOWN");
DeleteObjects("SQ6#DOWN");
DeleteObjects("SQ7#DOWN");
DeleteObjects("SQ1#UP");
DeleteObjects("SQ2#UP");
DeleteObjects("SQ3#UP");
DeleteObjects("SQ4#UP");
DeleteObjects("SQ5#UP");
DeleteObjects("SQ6#UP");
DeleteObjects("SQ7#UP");
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
switch (Digits()){
case 1: Digitos = 10;
case 2: Digitos = 100;
case 3: Digitos = 1000;
case 4: Digitos = 10000;
case 5: Digitos = 100000;
}   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
datetime TempoAtual = TimeCurrent();
string TempoDia = TimeToString(TempoAtual,TIME_DATE);
int Barras = Bars(Symbol(),PERIOD_CURRENT,TempoDia,TempoAtual);

ArraySetAsSeries(High,true);
ArraySetAsSeries(Low,true);

CopyHigh(Symbol(),PERIOD_CURRENT,0,Barras,High);
CopyLow(Symbol(),PERIOD_CURRENT,0,Barras,Low);

HighestCandle = ArrayMaximum(High,0,Barras);
LowestCandle = ArrayMinimum(Low,0,Barras);

MqlRates PriceInformation[];

ArraySetAsSeries(PriceInformation,true);

int Data = CopyRates(Symbol(),PERIOD_CURRENT,0,Barras,PriceInformation);

double HighestPrice = PriceInformation[HighestCandle].high;
double LowestPrice = PriceInformation[LowestCandle].low;

////////////////////////////////////////////////////////////////////////////////////////////////
if(Highest==true){
DeleteObjects("SQ1#DOWN");
DeleteObjects("SQ2#DOWN");
DeleteObjects("SQ3#DOWN");
DeleteObjects("SQ4#DOWN");
DeleteObjects("SQ5#DOWN");
DeleteObjects("SQ6#DOWN");
DeleteObjects("SQ7#DOWN");

int InitialPoint = iHighest(NULL,0,MODE_HIGH,Barras);
Time = iTime(Symbol(),PERIOD_CURRENT,InitialPoint);

datetime line1 = Time + 60*60*3;
ObjectCreate(0,"Line1",OBJ_VLINE,0,line1,0);
ObjectSetInteger(0,"Line1",OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,"Line1",OBJPROP_WIDTH,1);

datetime line2 = Time + 60*60*6;
ObjectCreate(0,"Line3",OBJ_VLINE,0,line2,0);
ObjectSetInteger(0,"Line3",OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,"Line3",OBJPROP_WIDTH,1);

datetime line3 = Time + 60*60*9;
ObjectCreate(0,"Line5",OBJ_VLINE,0,line3,0);
ObjectSetInteger(0,"Line5",OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,"Line5",OBJPROP_WIDTH,1);

datetime line4 = Time + 60*60*12;
ObjectCreate(0,"Line6",OBJ_VLINE,0,line4,0);
ObjectSetInteger(0,"Line6",OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,"Line6",OBJPROP_WIDTH,1);

datetime line5 = Time + 60*60*15;
ObjectCreate(0,"Line7",OBJ_VLINE,0,line5,0);
ObjectSetInteger(0,"Line7",OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,"Line7",OBJPROP_WIDTH,1);

datetime line6 = Time + 60*60*18;
ObjectCreate(0,"Line9",OBJ_VLINE,0,line6,0);
ObjectSetInteger(0,"Line9",OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,"Line9",OBJPROP_WIDTH,1);

Price = LowestPrice*Digitos;

double sq1 = MathSqrt(Price);

double vsq1 = (sq1 * (sq1 + 0.4))/Digitos;
double vsq2 = (sq1 * (sq1 + 0.9))/Digitos;
double vsq3 = (sq1 * (sq1 + 1.4))/Digitos;
double vsq4 = (sq1 * (sq1 + 1.9))/Digitos;
double vsq5 = (sq1 * (sq1 + 2.4))/Digitos;
double vsq6 = (sq1 * (sq1 + 2.9))/Digitos;
double vsq7 = (sq1 * (sq1 + 3.4))/Digitos;

ObjectCreate(0,"SQ1#UP",OBJ_HLINE,0,0,vsq1);
ObjectSetInteger(0,"SQ1#UP",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ1#UP",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ1#UP",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate(0,"SQ2#UP",OBJ_HLINE,0,0,vsq2);
ObjectSetInteger(0,"SQ2#UP",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ2#UP",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ2#UP",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate(0,"SQ3#UP",OBJ_HLINE,0,0,vsq3);
ObjectSetInteger(0,"SQ3#UP",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ3#UP",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ3#UP",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate(0,"SQ4#UP",OBJ_HLINE,0,0,vsq4);
ObjectSetInteger(0,"SQ4#UP",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ4#UP",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ4#UP",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate(0,"SQ5#UP",OBJ_HLINE,0,0,vsq5);
ObjectSetInteger(0,"SQ5#UP",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ5#UP",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ5#UP",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate(0,"SQ6#UP",OBJ_HLINE,0,0,vsq6);
ObjectSetInteger(0,"SQ6#UP",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ6#UP",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ6#UP",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate(0,"SQ7#UP",OBJ_HLINE,0,0,vsq7);
ObjectSetInteger(0,"SQ7#UP",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ7#UP",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ7#UP",OBJPROP_STYLE,STYLE_SOLID);
}

if(Lowest==true){
DeleteObjects("SQ1#UP");
DeleteObjects("SQ2#UP");
DeleteObjects("SQ3#UP");
DeleteObjects("SQ4#UP");
DeleteObjects("SQ5#UP");
DeleteObjects("SQ6#UP");
DeleteObjects("SQ7#UP");

int InitialPoint = iLowest(NULL,0,MODE_HIGH,Barras);
Time = iTime(Symbol(),PERIOD_CURRENT,InitialPoint);

datetime line1 = Time + 60*60*3;
ObjectCreate(0,"Line1",OBJ_VLINE,0,line1,0);
ObjectSetInteger(0,"Line1",OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,"Line1",OBJPROP_WIDTH,1);

datetime line2 = Time + 60*60*6;
ObjectCreate(0,"Line3",OBJ_VLINE,0,line2,0);
ObjectSetInteger(0,"Line3",OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,"Line3",OBJPROP_WIDTH,1);

datetime line3 = Time + 60*60*9;
ObjectCreate(0,"Line5",OBJ_VLINE,0,line3,0);
ObjectSetInteger(0,"Line5",OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,"Line5",OBJPROP_WIDTH,1);

datetime line4 = Time + 60*60*12;
ObjectCreate(0,"Line6",OBJ_VLINE,0,line4,0);
ObjectSetInteger(0,"Line6",OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,"Line6",OBJPROP_WIDTH,1);

datetime line5 = Time + 60*60*15;
ObjectCreate(0,"Line7",OBJ_VLINE,0,line5,0);
ObjectSetInteger(0,"Line7",OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,"Line7",OBJPROP_WIDTH,1);

datetime line6 = Time + 60*60*18;
ObjectCreate(0,"Line9",OBJ_VLINE,0,line6,0);
ObjectSetInteger(0,"Line9",OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,"Line9",OBJPROP_WIDTH,1);

Price = LowestPrice*Digitos;

double sq1 = MathSqrt(Price);

double vsq1 = (sq1 * (sq1 + 0.4))/Digitos;
double vsq2 = (sq1 * (sq1 + 0.9))/Digitos;
double vsq3 = (sq1 * (sq1 + 1.4))/Digitos;
double vsq4 = (sq1 * (sq1 + 1.9))/Digitos;
double vsq5 = (sq1 * (sq1 + 2.4))/Digitos;
double vsq6 = (sq1 * (sq1 + 2.9))/Digitos;
double vsq7 = (sq1 * (sq1 + 3.4))/Digitos;

ObjectCreate(0,"SQ1#DOWN",OBJ_HLINE,0,0,vsq1);
ObjectSetInteger(0,"SQ1#DOWN",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ1#DOWN",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ1#DOWN",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate(0,"SQ2#DOWN",OBJ_HLINE,0,0,vsq2);
ObjectSetInteger(0,"SQ2#DOWN",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ2#DOWN",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ2#DOWN",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate(0,"SQ3#DOWN",OBJ_HLINE,0,0,vsq3);
ObjectSetInteger(0,"SQ3#DOWN",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ3#DOWN",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ3#DOWN",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate(0,"SQ4#DOWN",OBJ_HLINE,0,0,vsq4);
ObjectSetInteger(0,"SQ4#DOWN",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ4#DOWN",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ4#DOWN",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate(0,"SQ5#DOWN",OBJ_HLINE,0,0,vsq5);
ObjectSetInteger(0,"SQ5#DOWN",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ5#DOWN",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ5#DOWN",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate(0,"SQ6#DOWN",OBJ_HLINE,0,0,vsq6);
ObjectSetInteger(0,"SQ6#DOWN",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ6#DOWN",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ6#DOWN",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate(0,"SQ7#DOWN",OBJ_HLINE,0,0,vsq7);
ObjectSetInteger(0,"SQ7#DOWN",OBJPROP_COLOR,colorHLINE);
ObjectSetInteger(0,"SQ7#DOWN",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"SQ7#DOWN",OBJPROP_STYLE,STYLE_SOLID);
}
//--- return value of prev_calculated for next call
   return(rates_total);
  }
  
//+------------------------------------------------------------------+
Reason: