Short Horizontal Line Weekend

 
Hi, I draw short horizontal lines using this code 
Line=Time[a]+(PeriodSeconds()*HlineBars);

It draws shorter lines if there's weekend, I want to fix it, how do I fix it?


Thanks in advance

 
Hgu Gh:
Hi, I draw short horizontal lines using this code 

It draws shorter lines if there's weekend, I want to fix it, how do I fix it?


Thanks in advance

Hi

int added_seconds=0;
int last_bar=a-HlineBars;
if(last_bar<0){
added_seconds=(int)(MathAbs(last_bar))*PeriodSeconds();
last_bar=0;
}
Line=(datetime)(Time[last_bar]+added_seconds);
 
Hgu Gh: It draws shorter lines if there's weekend, I want to fix it, how do I fix it?
Line=Time[a]+(PeriodSeconds()*HlineBars);
  1. Of course, it does. You assume that all bars exist — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
              "Free-of-Holes" Charts - MQL4 Articles (2006)
              No candle if open = close ? - MQL4 programming forum (2010)

  2. Get Time[a-HlineBars], do not assume. If that is in the future (a < HlineBars), then use maximum date and fix the result later.

    #define  MAX_DATETIME   D'3000.12.31 23:59:59'
 
Lorentzos Roussos #:

Hi

Thanks for your answer, but it doesn't solves it, weekends-market holidays and minutes wihout ticks during asian session make my lines shorter. I also want to draw lines into the future
 
William Roeder #:
  1. Of course, it does. You assume that all bars exist — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
              "Free-of-Holes" Charts - MQL4 Articles (2006)
              No candle if open = close ? - MQL4 programming forum (2010)

  2. Get Time[a-HlineBars], do not assume. If that is in the future (a < HlineBars), then use maximum date and fix the result later.

Thanks for your response, could you please tell me how to use maximum date and fix the result? Give me a code example please
 
Hgu Gh #: could you please tell me how to use maximum date and fix the result? Give me a code example please
Line=Time[a]+(PeriodSeconds()*HlineBars);

I have no idea what "a" is, or it's context. On a new bar adjust the endpoints.

Not tested, not compiled, just typed.

void adjust_endpoints(){
   int prefixLength = StringLength(LINE_PREFIX);
   for(int i=ObjectsTotal()-1; i >= 0; --i){
      string name=ObjectName(i);
      if(StringSubString(name, 0, prefixLength) == LINE_PREFIX){
          datetime start = (datetime) ObjectGetInteger(0, name, OBJPROP_TIME); 
          double   price = ObjectGetDouble(0, name, OBJPROP_PRICE);
          int a = iBarShift(_Symbol, _Period, start);
          if(a >= HlineBars) ObjectMove(name, 1, Time[a-HlineBars], price);
}  }  }
void create_line(int ibar, double price){
   datetime begin = Time[iBar];
   string name = LINE_PREFIX + string(Bars-1-iBar);
   objectCreate(name, OBJ_TREND, begin, price, MAX_DATETIME, price);
   ⋮   // https://docs.mql4.com/constants/objectconstants/enum_object/obj_trend
} 

Not tested, not compiled, just typed.

Do not use series index in object names, as they are not unique. As soon as a new bar starts, you will be trying to create a new name (e.g., “name0”), same, existing, previous, name (e.g., “name0” now on bar one.)

Use time (as int) or a non-series index:

#define  SERIES(I)   (Bars - 1 - I) // As-series to non-series or back.
 
William Roeder #:

I have no idea what "a" is, or it's context. On a new bar adjust the endpoints.

Not tested, not compiled, just typed.

Not tested, not compiled, just typed.

Do not use series index in object names, as they are not unique. As soon as a new bar starts, you will be trying to create a new name (e.g., “name0”), same, existing, previous, name (e.g., “name0” now on bar one.)

Use time (as int) or a non-series index:

Thanks again, how do i adjust the endpoint into the future to exclude market holidays, weekends, missing bars, etc? 
 
Hgu Gh #: , how do i adjust the endpoint into the future to exclude market holidays, weekends, missing bars, etc? 

Asked and previously answered at #2.2