draw_line in mt4 extend all over the graph helps

 

Hello, I currently have this indicator that I modify with some parameters by watching tutorials (I am not a programmer) this indicator marks the high and low in an hour range from 23:00 to 14:00 but what can I do so that the lines that draw the high and low fully extend?

#property copyright "Copyright © 2010"


#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Yellow



#define INDI_OBJ_NAME "high/low"

// Indicator parameters
string    Info1="<< high/low >>";
 int       OpenHour=23;        // Session opening hour. 
 int       CloseHour=14;       // Session closing hour. NOTE: Session closes 1 min before this hour.
bool      RangeAlarm=false;    // Alarm for when the range exceeds the range thresholdvalue
 int       RangeThreshold=40;  // Range alarm threshold 

color     RangeTextColor=Yellow;// Show label with current channel range
int       NrOfDays=1;         // Nr of past days to draw the session channel for
//extern bool      EnableDST=false;    // Daylight savings time. Add 1 hour to the open & close hours



// Indicator buffers
double miaHiBuffer[];
double miaLoBuffer[];

// Indicator data
string msIndicatorName;
string msVersion = "v0.91";

bool mbRunOnce;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,miaHiBuffer);
   SetIndexLabel(0,"High");
   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,miaLoBuffer);
   SetIndexLabel(1, "Low");
   SetIndexEmptyValue(1,EMPTY_VALUE);
      
   //---- Set Indicator Name
   msIndicatorName = "high/low custom time trading "+msVersion;
   IndicatorShortName(msIndicatorName);
   
   mbRunOnce=false;
   
   return(0);
  }


//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
  // Clear objects
  for(int i=ObjectsTotal()-1; i>-1; i--)
    if (StringFind(ObjectName(i),INDI_OBJ_NAME)>=0)  ObjectDelete(ObjectName(i));
  return(0);
}


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
  int iNewTicks;
  int iCountedBars;   
 
  // Get unprocessed ticks
  iCountedBars=IndicatorCounted();
  if(iCountedBars < 0) return (-1);
  iNewTicks=Bars-iCountedBars;
  
  // Draw old sessions
  if (mbRunOnce==false) {
    DrawPreviousSessions();    
    mbRunOnce=true;
  } //endif
  
  // Draw current session
  DrawCurrentSession(iNewTicks);
  
  // Exit
  return(0);
} //endfunction
//+------------------------------------------------------------------+

//-----------------------------------------------------------------------------
// function: GetSessionBars()
// Description: Get nr of bars for the session. There can be bars missing!
//-----------------------------------------------------------------------------
int GetSessionBars(int iSessionOpen, int iSessionClose, int iShift) {
  int i;
  int iNrOfBars=0;
  
  // Check DST
  // if (EnableDST==true) { 
  //   iSessionOpen=iSessionOpen+1;
  //   iSessionClose=iSessionClose+1;
  // }
  
  // Get nr of bars for the session.
  for (i=iShift; i<(Bars-iShift); i++) {    
    // Check for beginning hour
    if (TimeHour(Time[i])==iSessionOpen && TimeMinute(Time[i])==0)  {
      return(iNrOfBars);
    }
    
    // Double check to account for missing bars and weekends
    if (IsSessionActive(iSessionOpen,iSessionClose,Time[i])==false) {
      iNrOfBars--; // Break in data. Remove last bar.
      return(iNrOfBars);
    }
    
    iNrOfBars++;
  } // endfor
  // Unable to complete. Return 0.
  return(0);
}


//-----------------------------------------------------------------------------
// function: DrawCurrentSession()
// Description: Draw lines for current session.
//-----------------------------------------------------------------------------
void DrawCurrentSession(int iNewTicks) {
  int i,j;
  int iNrOfBars;
  double dSessionHigh;
  double dSessionLow;
  static int iRange=0;
  static bool bRangeAlarm=false;
 
  if (IsSessionActive(OpenHour,CloseHour-1,Time[0])==true) {
    
    // Get nr of bars for the session. There can be bars missing!
    iNrOfBars=GetSessionBars(OpenHour,CloseHour-1,0);
    
    // Find the highest and lowest data for specified nr of bars
    dSessionHigh=High[iHighest(NULL,0,MODE_HIGH,iNrOfBars+1,0)];
    dSessionLow=Low[iLowest(NULL,0,MODE_LOW,iNrOfBars+1,0)];

    // Draw session lines
    for(i=0; i<=iNrOfBars; i++) {
      miaHiBuffer[i]=dSessionHigh;
      miaLoBuffer[i]=dSessionLow;
    } //endfor
    
    
    
     
    
    
    // Range alert
    iRange=PriceToPips(dSessionHigh-dSessionLow);
    if (iRange>RangeThreshold && RangeAlarm==true) {
      if (bRangeAlarm==false) {
        Alert(msIndicatorName,", ",Symbol(),", Range: ",iRange);
        bRangeAlarm=true;
      } //endif
    } 
    else {
      bRangeAlarm=false;  
    } //endif
  } //endif
  else {
    
  }
} //endfunction


//-----------------------------------------------------------------------------
// function: DrawPreviousSessions()
// Description: Draw lines for previous days sessions in chart.
//-----------------------------------------------------------------------------
void DrawPreviousSessions() {
  int i,j;
  int iNrOfBars;
  double dSessionHigh;
  double dSessionLow;
  int iNrOfDays=0;
  string sLineId;
  string sRange;
  
  // Clear the indicator buffers
  for (i=0; i<Bars; i++) {
    miaHiBuffer[j]=EMPTY_VALUE;
    miaLoBuffer[j]=EMPTY_VALUE;   
  }
 
  // Draw asian session for old data
  i=0;
  while (i<Bars && iNrOfDays<NrOfDays) {
    if (TimeHour(Time[i])==CloseHour && TimeMinute(Time[i])==0) {
        
      // Get nr of bars for the session. There can be bars missing!
      iNrOfBars=GetSessionBars(OpenHour,CloseHour,i);
              
      // Find the highest and lowest data for specified nr of bars
      dSessionHigh=High[iHighest(NULL,0,MODE_HIGH,iNrOfBars,i+1)];
      dSessionLow=Low[iLowest(NULL,0,MODE_LOW,iNrOfBars,i+1)];
      
      // Draw session lines
      for(j=i+1; j<=i+iNrOfBars; j++) {    
        miaHiBuffer[j]=dSessionHigh;
        miaLoBuffer[j]=dSessionLow;    
      } //endfor    
      
      
      
      
      
     
      iNrOfDays++;  
    } //endif
  i++;
  } //end while
}


//-----------------------------------------------------------------------------
// function: DrawRangeValue()
// Description: Draw range text label below the high channel line
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// function: IsSessionActive()
// Description: Check if session is open. If DST is enabled add 1hr to the market time
//-----------------------------------------------------------------------------
int IsSessionActive(int iSessionOpen, int iSessionClose, datetime dBarTime) {
   int iBarHour; 
   int iBarMinute;
   bool bResult;
   iBarHour = TimeHour(dBarTime);
   iBarMinute = TimeMinute(dBarTime);
   
   // Check DST
   //if (EnableDST==true) { 
   //  iSessionOpen=iSessionOpen+1;
   //  iSessionClose=iSessionClose+1;
   //}
   
   // Check if market is open.
   if (iSessionOpen<iSessionClose) { 
      if (iBarHour>=iSessionOpen && iBarHour<=iSessionClose) 
        bResult=true; // Open & close before midnight
      else 
        bResult=false;
   }   
   else {  
     if (iBarHour>=iSessionOpen || iBarHour<=iSessionClose) 
       bResult=true; // Open before midnight and close after midnight
     else 
       bResult=false;
   }
   return(bResult);     
}

//-----------------------------------------------------------------------------
// function: DrawLine()
// Description: Draw a horizontal line at specific price
//----------------------------------------------------------------------------- 


//-----------------------------------------------------------------------------
// function: DrawTextLabel()
// Description: Draw a text label for a line
//-----------------------------------------------------------------------------



//-----------------------------------------------------------------------------
// function: PriceToPips()
// Description: Convert a proce difference to pips.
//-----------------------------------------------------------------------------
double PriceToPips(double dPrice) {

  if (Digits==2 || Digits==3) 
    return(dPrice/0.01); 
  else if (Digits==4 || Digits==5) 
    return(dPrice/0.0001); 
  else
    return(dPrice);            
} // end funcion()


//-----------------------------------------------------------------------------
// function: PipDigits()
// Description: Digits of the pips
//-----------------------------------------------------------------------------

 

Add "HighLine" in "DrawCurrentSession" as follow.

// Draw session lines
/*for(i = 0; i <= iNrOfBars; i++)
  {
     miaHiBuffer[i] = dSessionHigh;
     miaLoBuffer[i] = dSessionLow;
  } //endfor
*/
string objName = "HighLine";

if (ObjectFind(objName) < 0)
{
   ObjectCreate(objName, OBJ_HLINE, 0, Time[0], dSessionHigh);
   ObjectSet(objName, OBJPROP_COLOR, clrYellow);
   ObjectSet(objName, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(objName, OBJPROP_BACK, true);
}
else
{
   ObjectMove(objName, 0, Time[0], dSessionHigh);
}

Add "LowLine" in a similar way.

Add these 2 lines in "deinit".

ObjectDelete("HighLine");
ObjectDelete("LowLine");
 
Nagisa Unada:

Add "HighLine" in "DrawCurrentSession" as follow.

Add "LowLine" in a similar way.

Add these 2 lines in "deinit".

wow! Thank you very much it worked for me just as I needed it! grateful for your help

Reason: