Last bar on chart ? intra bar or closed ?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #12874 quote
    mark-uk
    Participant
    New
    Last bar on chart ?
    How to execute section of indicator code when at last bar on chart and not on previous bars ? ( Other sections of indicator code may well execute on every bar )
    Intra bar or closed ?
    How to know …. Is last bar on chart mid way through formation or closed ?
    #12878 quote
    Nicolas
    Keymaster
    Master

    About last bar on chart, since we can’t know if the current barindex is the last one, you can make use of Time and CurrentTime and compare their values.

    For your second question, if the bar is closed, that’s already happened and you are already in the next intra bar. So every Close[0] you can test, in real time are intra bar as long as it is not closed. You can also make use of time comparison to know you are still in the current bar.

    #12881 quote
    mark-uk
    Participant
    New

    Thank you Nicolas for replying and so quickly.

    Not sure how Time and CurrentTime might work for static charts, instruments not trading over weekend, etc

    Perhaps you could show us by writing a LastBarOnChart function that worked for most data & timeframe & tick chart scenarios.

    Perhaps you could also have a go at an IntraBar function that when called returned something like …
    1 – Opening tick of bar
    2 – Closing tick of bar
    3 – IntraBar tick

    I would personally find these very useful for coding in PRC and use them often as i’m sure others would.
    Many many thanks in advance
    Mark 🙂

    #12885 quote
    Nicolas
    Keymaster
    Master

    Something like this would work to get the last bar on chart:

    LastBarOnChart = date=today and currenttime<time+1 and currenttime<>time
    
    return LastBarOnChart

    About the other things, could you provide us more explanation and how you’d like to use it?

    undefined thanked this post
    #12905 quote
    mark-uk
    Participant
    New

    Brilliant Nicolas LastBarOnChart function appears to work really well, thank you, great work !

    Some scenario’s Bar Status function might be useful for …
    1. count how many times intrabar a particular price level is touched
    OR
    2. a user monitoring charts might employ a text alert for when a new bar starts or current bar closes
    OR
    3. indicator is based on Open values and only needs to calculate on 1st tick of a new bar
    OR
    4. capturing indicator extremes ( OB/OS ) intrabar

    #56761 quote
    Nicolas
    Keymaster
    Master

    Another solution to get the last barindex can be found in this topic: How to know EOF? the last barindex?

    #103028 quote
    undefined
    Participant
    Master

    Depending on what time zone the instrument is trading at, you probably have to adjust to:

    (70000 is 7 hour difference between Paris Timezone and Chicago Timezone)

    LastBarOnChart = date=today and currenttime+70000<time+1 and currenttime+70000<>time
    
    return LastBarOnChart
    
    Nicolas thanked this post
    #109130 quote
    John Doe
    Participant
    Senior

    Hello Nicolas,

    I have the impression that the code snippet that you proposed for the LastBarOnChart does not work anymore in prorealtime V11. Do you have another suggestion
    that I can try to identity the last bar on the chart in V11?

     

    Thanks!

    blade106 thanked this post
    #112149 quote
    blade106
    Participant
    New

    Hello Nicolas,

    As stated by John Doe, this code doesn’t work anymore on PRT v11. «TODAY» and «DATE» return exactly the same information on each bar. Same with «TIME» and «CURRENTTIME».

    Also «CURRENTDAY» is really missing… How difficult would it be to add it in a next minor version?

    My usage: you’ve created some fractal indicators, which work great. But on the last bars, nothing is detected, because we have a lookback of N bars. Hence, with a lookback of 10 bars, at day 100, I can only detect a pike at day 90. If I could count the number of bars between a specific bar and today, that would help reducing the lookback progressively. And detect latest pikes!

    In fact, it’s not CURRENTDAY that would help, but DAYS and a new CURRENTDAYS. This way we can compute how much bars from TODAY we have.

    Thanks!

    #112161 quote
    Nicolas
    Keymaster
    Master

    You are right, TODAY was a great workaround to reduce the calculation and your example is perfect.

    However, I had confirmation that a new instruction should be available this week or the next one (in version 11) that replace what we used to do with TODAY. This new keyword will return a boolean value each time the last bar on chart is updated.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Last bar on chart ? intra bar or closed ?


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
mark-uk @mark-uk Participant
Summary

This topic contains 9 replies,
has 5 voices, and was last updated by Nicolas
6 years, 3 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/08/2016
Status: Active
Attachments: 1 files
Logo Logo
Loading...