Indicator for bar duration

Forums ProRealTime English forum ProBuilder support Indicator for bar duration

Viewing 12 posts - 1 through 12 (of 12 total)
  • #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

    #42503

    Does something like this work?

     

    #42519

    Time 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

    #42527

    Hi,

    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.

     

    #42531

    Use 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.

    #42532

    Hi 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.

    #42534

    Code 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…

    #44794

    If someone needs it….

     

    2 users thanked author for this post.
    #44829

    @Alberto

    Thanks for your indicator, I will certainly add it to the Library if you don’t mind. Very useful!

    #44841

    @Nicolas

    you can add it wherever you think is best suited for the forum users

    #219449

    Hello, 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.

    #219486

    To get a bar duration in seconds, you can make a subtract between the current timestamp and the timestamp of the Open:

    However, a 5-minutes bar will also last 300 seconds 😉

Viewing 12 posts - 1 through 12 (of 12 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login