how to get the date of t2 for a trend line

 

hi

i have a simple indicator which draw a trend line horizontally and to the right , can we get the date of the t2 for that trend line using any code? (even if the trend line extended out the range of the trading bar)?

as in the attached pic

//+------------------------------------------------------------------+
//|                                               futurbar.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

extern string LineName="Line1";
extern double Barsahead=90;
extern bool UseAutoDateTime=true;
extern datetime StartTime=D'2018.07.05 18:00';
extern datetime EndTime=D'2018.07.05 18:00';

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   if(UseAutoDateTime){
  double a=ObjectGet(LineName,OBJPROP_TIME1);
  double b=ObjectGet(LineName,OBJPROP_TIME2);
  StartTime=MathMin(a,b);
  EndTime=MathMax(a,b);
  }
  {
       /*  int shif=iBarShift(Symbol(),0,StartTime,false);
     int shif2=iBarShift(Symbol(),0,EndTime,false);
     int shif3=iBarShift(Symbol(),0,StartTime,false);
     int shif33=iBarShift(Symbol(),0,EndTime,false);
  int shif4=iBarShift(Symbol(),0,EndTime,false);*/
     
              }
  
int xxx=Barsahead+Barsahead*PeriodSeconds();
int yyy;
  int start_bar_shift=iBarShift(Symbol(),0,StartTime);
  int end_bar_shift=start_bar_shift-Barsahead;
    if(end_bar_shift>=0)
       yyy=Time[end_bar_shift];
  else
     yyy= StartTime+xxx;//* // 
     
                    
        ObjectDelete ("ObjName");
       ObjectCreate("ObjName",OBJ_TREND,0,StartTime,Low[0],yyy,Low[0]);//+SlopeUnit)
      ObjectSet("ObjName",OBJPROP_RAY, false); 
       
                       return(0);
  }
//+------------------------------------------------------------------+
Files:
GBPUSDH1.png  19 kb
 
datetime dt = (datetime)ObjectGetInteger(ChartID(), "trendline_name", OBJPROP_TIME, 1);
 
Yashar Seyyedin #:
ChartID()

thanks for your help...but sorry am not a programmer iv change your code to 

     datetime dt = (datetime)ObjectGetInteger(ChartID(), "ObjName", OBJPROP_TIME, 1);

some time  when i change the  value 

extern double Barsahead

and i get a date of   2024.06.02 10:01....

from the terminal  the result is  in yyyy.mm.dd hh:mm  with an extra menute  (10:01) ...but am using a H1 chart only

as when i insert 90 for Barseahead which extend the horizontal trend line outside the range of existing bars 

you can tray it 

 
abd-:
int xxx=Barsahead+Barsahead*PeriodSeconds();

This line is meaningless. Barsahead is in units of bar count. While PeriodSeconds is in seconds unit.

If you are using AI generative code please don't... You should study well organized handbooks if you want to learn coding.

 
Yashar Seyyedin #:
If you are using AI generative code please don't... You should study well organized handbooks if you want to learn coding.

hi and thanks for your help  ....this line of code was giving to me by a group member ..and before the use of AI code generation  ^-^.

some times i think about  learn coding but because i dont have enough time and at the same time my code is simple and not requierd deep understanding of  coding i went over the internet to find a solution for any problem about that .

thanks for your help 

 
Anyway I couldn't understand your problem and what output you expect.
 
Yashar Seyyedin #:
Anyway I couldn't understand your problem and what output you expect.

hi

thanks for your kindness in trying to help me ..i appreciate ....and sorry for my weak English which cause this misunderstanding .

i attached a pic which explain the problem ...and  i will tray to solve it  as i think the problem is emerging from this line 

int xxx=Barsahead+Barsahead*PeriodSeconds();

as  you said  ;

Barsahead is in units of bar count. While PeriodSeconds is in seconds unit.

thanks very much 

Files:
GBPUSDH2.png  44 kb
 
abd- #:
xxx=Barsahead+Barsahead*PeriodSeconds()
Try this : xxx=Barsahead*PeriodSeconds()
 
Yashar Seyyedin #:
Try this : xxx=Barsahead*PeriodSeconds()

this work very good and solve the problem......

thanks very much and appreciated