Making Trend lines that don't start from infinity and continue to infinity

 
I have a function that creates trend lines from one point in an array to a third point but i cannot stop it from creating lines that start and and end at ininfiy .
The trend lines it creates are from an array thats filled by another function , the point of the array filling function is to find higherlows and lowerhighs and then fill an array with the prices and times . I wanted the DrawTrendLines function to just draw trend lines between the first point to and third point , not start from infinity and not continue to infinity . I tried setting OBJPROP_RAY to false but it just make things worse and made the trend lines look completetly different from what i wanted 
void OnTick()
{
  int size = 100;
  double prices[100];
  if (CopyClose(Symbol(), Period(), 0, size, prices) != size)
  {
    Print("Error copying closing prices");
    return;
  }
  DrawTrendLine(size, prices);
}

void HigherLowsAndLowerHighs(int size, double &prices[], datetime &timesHL[], double &pricesHL[], datetime &timesLH[], double &pricesLH[])
{
  int hlIndex = 0;
  int lhIndex = 0;
  for (int i = 1; i < size; i++)
  {
    if (prices[i] > prices[i - 1])
    {
      timesHL[hlIndex] = iTime(Symbol(), Period(), i);
      pricesHL[hlIndex] = prices[i];
      hlIndex++;
    }
    if (prices[i] < prices[i - 1])
    {
      timesLH[lhIndex] = iTime(Symbol(), Period(), i);
      pricesLH[lhIndex] = prices[i];
      lhIndex++;
    }
  }
}

/* void DrawTrendLine(int size, double &prices[])
{
  double pricesHL[100];
  double pricesLH[100];
  datetime timesHL[100];
  datetime timesLH[100];

  HigherLowsAndLowerHighs(size, prices, timesHL, pricesHL, timesLH, pricesLH);

  for (int i = 0; i < size - 2; i++)
  {
    if (pricesHL[2] != 0)
    {
      string trendLineName = "trendLine_HL_" + IntegerToString(i);
      ObjectCreate(trendLineName, OBJ_TREND, 0, timesHL[i], pricesHL[i], timesHL[i + 2], pricesHL[i + 2]);
      ObjectSet(trendLineName, OBJPROP_COLOR, clrGreen);
      ObjectSet(trendLineName, OBJPROP_RAY, false);
    }
    if (pricesLH[2] != 0)
    {
      string trendLineName = "trendLine_LH_" + IntegerToString(i);
      ObjectCreate(trendLineName, OBJ_TREND, 0, timesLH[i], pricesLH[i], timesLH[i + 2], pricesLH[i + 2]);
      ObjectSet(trendLineName, OBJPROP_COLOR, clrRed);
      ObjectSet(trendLineName, OBJPROP_RAY, false);
    }
  }
}  */

void DrawTrendLine(int size, double &prices[])
{
  double pricesHL[100];
  double pricesLH[100];
  datetime timesHL[100];
  datetime timesLH[100];

  HigherLowsAndLowerHighs(size, prices, timesHL, pricesHL, timesLH, pricesLH);

  for (int i = 0; i < size - 2; i++)
  {
    if (pricesHL[2] != 0)
    {
      string trendLineName = "trendLine_HL_" + IntegerToString(i);
      ObjectCreate(trendLineName, OBJ_TREND, 0, timesHL[i], pricesHL[i], timesHL[i + 2], pricesHL[i + 2]);
      ObjectSet(trendLineName, OBJPROP_COLOR, clrGreen);
      
    }
    if (pricesLH[2] != 0)
    {
      string trendLineName = "trendLine_LH_" + IntegerToString(i);
      ObjectCreate(trendLineName, OBJ_TREND, 0, timesLH[i], pricesLH[i], timesLH[i + 2], pricesLH[i + 2]);
      ObjectSet(trendLineName, OBJPROP_COLOR, clrRed);
      
    }
  }
}
Documentation on MQL5: Array Functions / ArrayFill
Documentation on MQL5: Array Functions / ArrayFill
  • www.mql5.com
ArrayFill - Array Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Mihlali Linge Dlulane but i cannot stop it from creating lines that start and and end at ininfiy .

Turn off both Ray attributes. See the example OBJ_TREND - Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5

Reason: