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 !!
I hope the answer is simple.
- 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 - Just draw your line, turn on the ray. Move the endpoint when new bars form if necessary.
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;
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 :)
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 !!
- 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 - Just draw your line, turn on the ray. Move the endpoint when new bars form if necessary.
Thx for your great reply !
TimeCurrent()+PeriodSeconds()*(x bars to the right)
TimeCurrent()+PeriodSeconds()*(x bars to the right)
Hi Mladen,
i have the similar problem. Lets say my local time is GMT+4, and my server time is GMT+2. Now is Wednesday , April 29,2020 at 08:00 MT4 server time (lastbar, i=0). I use TF H4 for this, and i want to know the day & time of 100 bars in the future ...How to do that ?
input int amountOfBars = 100; datetime curBarTime,localTime,serverTime,futureBarTime; int candleSecs,weeksAmount; string targetDay,targetTime; //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { curBarTime = iTime(NULL,0,0); candleSecs = PeriodSeconds()*amountOfBars; weeksAmount = (int) MathFloor(candleSecs/(5*24*60*60)); futureBarTime = curBarTime+candleSecs; // targetDay = ?? // targetTime = ?? //--- return value of prev_calculated for next call return(rates_total); }
Any idea is very welcome ....
Thank you very much in advance.
= jack
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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 !!