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);
Line=Time[a]+(PeriodSeconds()*HlineBars);
-
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) -
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'
-
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) -
Get Time[a-HlineBars], do not assume. If that is in the future (a < HlineBars), then use maximum date and fix the result later.
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.
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:

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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