# How to convert bars in the future to time ?

258

Hi, I'm struggling with the problem that I can not convert future bars to a timestamp; I need this for graphical presentations of trendlines and I want to exclude weekends and hollidays. It's not solved by adding to the current time, x PeriodSeconds(bar period)  .

To be more specific: TimeCurrent() + (x bars to the right) = which time  ?

I hope the answer is simple. TimeCopy is unfortunately only based on history bars and not future bars.

Thx for your advice !!

110354

Daniel Weckhuyzen:

Hi, I'm struggling with the problem that I can not convert future bars to a timestamp; I need this for graphical presentations of trendlines and I want to exclude weekends and hollidays. It's not solved by adding to the current time, x PeriodSeconds(bar period)  .

To be more specific: TimeCurrent() + (x bars to the right) = which time  ?

I hope the answer is simple. TimeCopy is unfortunately only based on history bars and not future bars.

Thx for your advice !!

TimeCurrent()+PeriodSeconds()*(x bars to the right)
17927

Daniel Weckhuyzen: I can not convert future bars to a timestamp; I need this for graphical presentations of trendlines and I want to exclude weekends and hollidays. It's not solved by adding to the current time, x PeriodSeconds(bar period)

I hope the answer is simple.

1. You can't generally predict future bar times. Time + n PeriodSeconds assumes every bar every exists. 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
No candle if open = close ? - MQL4 and MetaTrader 4 - MQL4 programming forum

2. Just draw your line, turn on the ray. Move the endpoint when new bars form if necessary.
258

Thx for your reply guys;

What I would like to do is draw an equidistant channel, but in an harmonic way; for instance I have a certain reference bar (which forms a top or a bottom) and want to draw an harmonic numbers of bars to the right, my channel. There I want to stop my channel; when there's a weekend in between (so I can not use "TimeCurrent()+PeriodSeconds()*(x bars to the right)"), I have a problem; In order to avoid messing up my screen, I don't want to use the 'ray' option;

22059

Daniel Weckhuyzen:

Thx for your reply guys;

What I would like to do is draw an equidistant channel, but in an harmonic way; for instance I have a certain reference bar (which forms a top or a bottom) and want to draw an harmonic numbers of bars to the right, my channel. There I want to stop my channel; when there's a weekend in between (so I can not use "TimeCurrent()+PeriodSeconds()*(x bars to the right)"), I have a problem; In order to avoid messing up my screen, I don't want to use the 'ray' option;

Simply when you use TimeCurent()+PeriodSeconds*BarsCount X as you set the resulting time as the ending point for your trend line or channel you get 2 options

A- when the future time hasn't come yet then there is no problem because there is no bar with this time formed yet so the Line will be plot normally at the time you specified to the right of the Chart

B- if the time that resulted from this equation doesn't exist " there is no bar with this time" due to weekend or what ever reason but however there is bar with a time that is beyond the resulting time then instead of using time use the number of bars required for instance if the number of bars you wnt to add is 10 then you just need to check subtract the index of the beginning bar from the bars count to get the index of the ending bar say the index of starting bar is 50 then you need to subtract 10 bars from it you got index of 40 . this will make you depend on bars count rather than time which will be more accurate . hope you can understand what I mean . in short use IINDEX instead of TIME

Setps :

1= Use IBarShift() to determine the index of the first Anchor Point of your Cahnnel or Trend Line

2- Subtract the number of bars from the Starting Index  50-30=20+1=21

3- set the ending time as Time[Ending Index]

4- problem solved :)

258

Mohamed Nabil:

Simply when you use TimeCurent()+PeriodSeconds*BarsCount X as you set the resulting time as the ending point for your trend line or channel you get 2 options

A- when the future time hasn't come yet then there is no problem because there is no bar with this time formed yet so the Line will be plot normally at the time you specified to the right of the Chart

B- if the time that resulted from this equation doesn't exist " there is no bar with this time" due to weekend or what ever reason but however there is bar with a time that is beyond the resulting time then instead of using time use the number of bars required for instance if the number of bars you wnt to add is 10 then you just need to check subtract the index of the beginning bar from the bars count to get the index of the ending bar say the index of starting bar is 50 then you need to subtract 10 bars from it you got index of 40 . this will make you depend on bars count rather than time which will be more accurate . hope you can understand what I mean . in short use IINDEX instead of TIME

Setps :

1= Use IBarShift() to determine the index of the first Anchor Point of your Cahnnel or Trend Line

2- Subtract the number of bars from the Starting Index  50-30=20+1=21

3- set the ending time as Time[Ending Index]

4- problem solved :)

Thx Mohamed, good advice ! I'll try it out !

A big thank you !!

258

whroeder1:
1. You can't generally predict future bar times. Time + n PeriodSeconds assumes every bar every exists. 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
No candle if open = close ? - MQL4 and MetaTrader 4 - MQL4 programming forum

2. Just draw your line, turn on the ray. Move the endpoint when new bars form if necessary.

Thx for your great reply !

258

Mladen Rakic:
TimeCurrent()+PeriodSeconds()*(x bars to the right)
Thx Mladen !
To add comments, please log in or register