Indicator for bar duration
Forums › ProRealTime English forum › ProBuilder support › Indicator for bar duration
- This topic has 11 replies, 2 voices, and was last updated 1 year ago by Nicolas.
-
-
08/04/2017 at 10:38 PM #42489
Hi all,
I’m using tick bars and I would need an indicator that plots how long did every bar last (in seconds); is that possible? If yes, could you please give me an hint?
Thanks,
Alberto
08/05/2017 at 1:59 PM #4250308/06/2017 at 1:26 AM #42519Time seems to return the bar open time in format hhmmss; in any other programming language I would use the bitwise operator & to calculate the seconds elapsed; something like that
<pre class=”lang:probuilder decode:true “>bt = Time-Time[1]BarDuration = (bt & 0xFF0000)*3600 + (bt & 0x00FF00)*60 + (bt & 0x0000FF)
How could I do that in prorealtime?Thanks,
Alberto
08/06/2017 at 10:04 AM #42527Hi,
just a quick moderation message: please update your country flag by selecting a location in your profile settings. Thank you 🙂
Please see pdf manuals from help menu of the platform, “time” is the closing time of a bar, and “opentime” is the opening time of a bar.
For a cfd x ticks chart, you would know when the current x ticks bar starts, but unlike for classical “pure time” timeframes (1mn, 1h, 1day etc…) with an x ticks bar you wouldn’t know when it ends as long as it’s not complete yet… so using “time” keyword in a code for x ticks charts is not going to work because code is read on current bar and end of current x ticks bar is not yet known. I hope older forum members will forgive me for being a parrot on this subject: you would be better off working with “opentime” keyword when it comes to x ticks charts.
So only when an x ticks bar is complete can you know how long it lasted, by making the difference between current new bar’s opentime, and the freshly complete previous bar’s opentime.
08/06/2017 at 11:10 AM #42531Use the above code from Wing in a 1-sec TF and you will get what you want, because in the “hhmmss” the “ss” part has meaningful data.
Instead, if you use the above code in 1-min TF you will see (with GRAPH) that “LastBarTime” will have at some point, say, 221500 (hhmmss), because the “ss” part is meaningless. In that case you simply have to divide “BarDuration” by 100, then multiply it by 60 to get the correct number of seconds, but it will always be 60 or a multiple of it, since “time” will always tell you the time of the next bar open, which, unless used in TFs expressed in seconds, will always be in minutes!
If you use the same code in a 1-hour TF you will have to divide it by 10000 (because also the “mm” part is meaningless) then multiply it by 3600.
So, to summerize, only a 1-sec TF will tell you exactly the numer of seconds elapsed, but in that case you don’t even need a special piece of code, you just have to count bars as they elapse.
As for ticks… I don’t know.
08/06/2017 at 11:20 AM #42532Hi Noobywan,
flag updated 😉
About the main request, as you can imagine I’m quite new to prorealtime; I read the docs but it’s still unclear to me how things work. I understood your point, so every indicator applied on a price different from open is one bar lagged?
Let me explain better with an example: using 1hour timeframe I won’t see the moving average applied on close price related to bar at 10.00 until the bar at 11.00 opens, isn’t it? In the platforms I used until now the indicator applied to the current bar is updated during the formation of that bar.
08/06/2017 at 11:29 AM #42534Code is applied to current bar, and for classic timeframes (seconds or minutes or hours etc…) you’ll see your indicator updated live during each move of currentbar, there’s no lag, like other platforms you used until now… What I described was only for x ticks charts when you can’t know in advance when a bar ends until it’s ended, so only for those would you have info one bar later, this is by definition of construction of x ticks bars independant of time, not by platform type…
08/29/2017 at 8:36 AM #44794If someone needs it….
1234567891011121314151617181920212223242526272829303132333435363738394041424344// utilizzato nelle barre a tick, o comunque non a tempo, per valutare la durata della barra in secondi// ritorna il numero di secondi trascorsi per il completamento di ogni singola barraptime = Time[1]ctime = Time// estraggo la differenza in oreif ctime>=10000 thenhend = (ctime - (ctime mod 10000))/10000ctime = (ctime mod 10000)elsehend = 0endifif ptime>=10000 thenhstart = (ptime - (ptime mod 10000))/10000ptime = (ptime mod 10000)elsehstart = 0endif// estraggo la differenza in minutiif ctime>=100 thenmend = (ctime - (ctime mod 100))/100ctime = (ctime mod 100)elsemend = 0endifif ptime>=100 thenmstart = (ptime - (ptime mod 100))/100ptime = (ptime mod 100)elsemstart = 0endifsecstarttime = hstart*3600+mstart*60+ptimesecendtime = hend*3600+mend*60+ctimebarsec = secendtime-secstarttime// correggo l'eventuale cambio di giornoif barsec<0 thenbarsec = 3600*24-secstarttime+secendtimeendifreturn barsec as "seconds/bar"08/29/2017 at 11:43 AM #4482908/29/2017 at 12:59 PM #44841you can add it wherever you think is best suited for the forum users
08/21/2023 at 4:45 PM #219449Hello, I would like to use this indicator seconds/bar inside my code but how to extract this data ?
I display this indicator below my graphic and then, how to read the seconds in my code using TF 5 minutes ?
Thank you and have a good day.
08/22/2023 at 1:59 PM #219486To get a bar duration in seconds, you can make a subtract between the current timestamp and the timestamp of the Open:
123duration = timestamp-opentimestampreturn duration as "bar duration in seconds"However, a 5-minutes bar will also last 300 seconds 😉
-
AuthorPosts
Find exclusive trading pro-tools on