How to draw Horizontal Line connecting two desired candles?

 

Dear Experts,

What would be the code if I want to draw a horizontal line connecting two candle highs from 5th bar to 29th bar??

Looking for possibility to draw horizontal line only between 5-29 bar not infinite line.

Any guidance will be highly appreciated.


Thanks

 
dbmlbm:

Dear Experts,

What would be the code if I want to draw a horizontal line connecting two candle highs from 5th bar to 29th bar??

Looking for possibility to draw horizontal line only between 5-29 bar not infinite line.

Any guidance will be highly appreciated.


Thanks

First of all, do you expect the 5th and 29th highs to be exactly the same? If not the line will not be horizontal.

Use a trend line.

 
Trend line with ray=false.
 

Dear Keith and William,

Thank you for responding to me.

I apologize for not being clear in my request. But what I need is to draw a horizontal line from 5th bar to 29th bar taking highest candle of 5-29 bar something like in the attached.

we are not comparing two candles but taking the highest high of a candle that is between 5th and 29th bar and then draw a Horizontal line from 5-29 bar no mater where was the highest candle.

Files:
 
dbmlbm: I apologize for not being clear in my request.
  1. Your want was clear.
  2. Get the HH between your candles. Create a trendline HH/Time[5] to HH/Time[29]
 

AIS INDICATOR 2 CANDLES CONNECTOR

AIS INDICATOR 2 CANDLES CONNECTOR


/******************************************************************************/
// AIS INDICATOR 2 CANDLES CONNECTOR                                          //
//============================================================================//
// DATA 1                                                                 //<  >
//------------------------------------------------------------------------//<-->
#property     copyright   "Copyright 2020, MetaQuotes Software Corp."     //< 1>
#property     link        "https://www.mql5.com"                          //< 2>
#property     version     "1.000"                                         //< 3>
#property     description "AIS AIRAT SAFIN"                               //< 4>
                                                                          //< 5>
string        NAME      = "AIS INDICATOR 2 CANDLES CONNECTOR"           ; //< 6>
long          CHART     =  NULL                                         ; //< 7>
int           WINDOW    =  NULL                                         ; //< 8>
                                                                          //< 9>
#property     indicator_chart_window                                      //<10>
#property     indicator_buffers    1                                      //<11>
#property     indicator_plots      1                                      //<12>
                                                                          //<13>
#define       E_TF ENUM_TIMEFRAMES                                        //<14>
                                                                          //<15>
string        SYMBOL    = _Symbol                                       ; //<16>
E_TF          PERIOD    = _Period                                       ; //<17>
//============================================================================//
// AIS AIRAT SAFIN                                           2020-05-06 19:57 //
/******************************************************************************/
// AIS INDICATOR 2 CANDLES CONNECTOR                                          //
//============================================================================//
// DATA 2                                                                 //<  >
//------------------------------------------------------------------------//<-->
sinput string S1="=================="; /* ============================ */ //< 1>
sinput int    CANDLE_FIRST    =  5   ; /* FIRST CANDLE                 */ //< 2>
sinput int    CANDLE_LAST     = 29   ; /* LAST  CANDLE                 */ //< 3>
sinput string S2="=================="; /* ============================ */ //< 4>
sinput int    LINE_WIDTH      =  3   ; /* LINE WIDTH                   */ //< 5>
sinput color  LINE_COLOR      = White; /* LINE COLOR                   */ //< 6>
sinput string S3="=================="; /* ============================ */ //< 7>
                                                                          //< 8>
                                                                          //< 9>
                                                                          //<10>
                                                                          //<11>
                                                                          //<12>
                                                                          //<13>
                                                                          //<14>
                                                                          //<15>
                                                                          //<16>
                                                                          //<17>
//============================================================================//
// AIS AIRAT SAFIN                                           2020-05-06 19:57 //
/******************************************************************************/
// AIS INDICATOR 2 CANDLES CONNECTOR                                          //
//============================================================================//
// FUNCTION 1                                                             //<  >
//------------------------------------------------------------------------//<-->
int    OnInit ()                                                        { //< 1>
                                                                          //< 2>
ObjectCreate     ( CHART , NAME , OBJ_TREND     , WINDOW      , 0 , 0 ) ; //< 3>
ObjectSetInteger ( CHART , NAME , OBJPROP_COLOR , LINE_COLOR          ) ; //< 4>
ObjectSetInteger ( CHART , NAME , OBJPROP_WIDTH , LINE_WIDTH          ) ; //< 5>
ObjectSetInteger ( CHART , NAME , OBJPROP_STYLE , STYLE_SOLID         ) ; //< 6>
ObjectSetInteger ( CHART , NAME , OBJPROP_BACK  , true                ) ; //< 7>
                                                                          //< 8>
                                                                          //< 9>
                                                                          //<10>
                                                                          //<11>
                                                                          //<12>
                                                                          //<13>
                                                                          //<14>
                                                                          //<15>
                                                                          //<16>
return INIT_SUCCEEDED                                                 ; } //<17>
//============================================================================//
// AIS AIRAT SAFIN                                           2020-05-06 19:57 //
/******************************************************************************/
// AIS INDICATOR 2 CANDLES CONNECTOR                                          //
//============================================================================//
// FUNCTION 2                                                             //<  >
//------------------------------------------------------------------------//<-->
void   OnDeinit     ( const int REASON )                                { //< 1>
                                                                          //< 2>
       ObjectDelete ( CHART   , NAME   )                                ; //< 3>
       ChartRedraw  ()                                                  ; //< 4>
                                                                          //< 5>
                                                                          //< 6>
                                                                          //< 7>
                                                                          //< 8>
                                                                          //< 9>
                                                                          //<10>
                                                                          //<11>
                                                                          //<12>
                                                                          //<13>
                                                                          //<14>
                                                                          //<15>
                                                                          //<16>
                                                                        } //<17>
//============================================================================//
// AIS AIRAT SAFIN                                           2020-05-06 19:57 //
/******************************************************************************/
// AIS INDICATOR 2 CANDLES CONNECTOR                                          //
//============================================================================//
// FUNCTION 3                                                             //<  >
//------------------------------------------------------------------------//<-->
int    OnCalculate (const int R,const int C,const int B,const double&P[]){//< 1>
                                                                          //< 2>
if   ( ! NEW_CANDLE () )  return  NULL                                  ; //< 3>
                                                                          //< 4>
datetime TIME_FIRST     = iTime ( SYMBOL , PERIOD , CANDLE_FIRST      ) ; //< 5>
datetime TIME_LAST      = iTime ( SYMBOL , PERIOD , CANDLE_LAST       ) ; //< 6>
                                                                          //< 7>
double   PRICE   = fmax ( iHigh ( SYMBOL , PERIOD , CANDLE_FIRST    ) ,   //< 8>
                          iHigh ( SYMBOL , PERIOD , CANDLE_LAST     ) ) ; //< 9>
                                                                          //<10>
ObjectSetInteger ( CHART , NAME , OBJPROP_TIME    , 0 , TIME_FIRST    ) ; //<11>
ObjectSetInteger ( CHART , NAME , OBJPROP_TIME    , 1 , TIME_LAST     ) ; //<12>
ObjectSetDouble  ( CHART , NAME , OBJPROP_PRICE   , 0 , PRICE         ) ; //<13>
ObjectSetDouble  ( CHART , NAME , OBJPROP_PRICE   , 1 , PRICE         ) ; //<14>
ChartRedraw      ()                                                     ; //<15>
                                                                          //<16>
return R                                                              ; } //<17>
//============================================================================//
// AIS AIRAT SAFIN                                           2020-05-06 19:59 //
/******************************************************************************/
// AIS INDICATOR 2 CANDLES CONNECTOR                                          //
//============================================================================//
// FUNCTION 4                                                             //<  >
//------------------------------------------------------------------------//<-->
int    NEW_CANDLE ()                                                    { //< 1>
                                                                          //< 2>
static datetime TIME_LAST = NULL                                        ; //< 3>
       datetime TIME_THIS = iTime ( SYMBOL , PERIOD , 0 )               ; //< 4>
                                                                          //< 5>
if   ( TIME_LAST < TIME_THIS )                                            //< 6>
     {                                                                    //< 7>
       TIME_LAST = TIME_THIS                                            ; //< 8>
                                                                          //< 9>
       return true                                                      ; //<10>
     }                                                                    //<11>
else   return NULL                                                      ; //<12>
                                                                          //<13>
                                                                          //<14>
                                                                          //<15>
                                                                          //<16>
                                                                        } //<17>
//============================================================================//
// AIS AIRAT SAFIN                                           2020-05-06 19:57 //
/******************************************************************************/
 
AIRAT SAFIN:

AIS INDICATOR 2 CANDLES CONNECTOR



Thats what I was looking for!

Thank you very very much Dear!

 
dbmlbm: Thats what I was looking for!

Someone to do it for you; you've learned nothing.