- ObjectCreate: Trying to draw a trend line with OBJ_TREND in MT4 between Highs - getting error in code
- draw horizontal line with right ray
- Indicators: Trendline Price Alert
You may try this solution:
datetime CorrectTime(datetime time, int bars_forward) { int counted=0; while(counted<bars_forward) { if(iBarShift(_Symbol, PERIOD_CURRENT, time, true)!=-1 || time>Time[0]) counted++; time+=PeriodSeconds(); } return time; }
A Tline is from time one to time two. It is not over bars.
You assume that every bar every exists — 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)
Hi
I don’t think that there is a better solution that going in a loop through history and count those 90 bars and find the times of the starting and ending point of the loop.
There is no universal way to work on times using bars only – just make your code base on available data from chart.
Best Regards

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use