Number of bars between two reference points

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #55481 quote
    ck1066
    Participant
    Average

    Hello,

    How do I find out the number of bars between two reference points is greater than X. Is there a function for this?

     

    Thanks.

    #55487 quote
    robertogozzi
    Moderator
    Master

    Bars are identified by their time.

    You know what TF your strategy is running on, so in a 30-minute TF the difference between, say, 100000 and 113000 will return 3 bars elapsed.

    Is that what you meant?

    #55491 quote
    ck1066
    Participant
    Average

    Thanks for your reply Robertogozzi but not quite what I meant.

    I want to know if point B has moved more than x bars from point A, irrespective of time-frame.

    So for example, if an instrument has retraced more than 6 bars before detecting a bullish engulfing candle

     

    #55497 quote
    robertogozzi
    Moderator
    Master

    I don’t know exactly what you mean, anyway when any event of your choice occurs tou may use BARINDEX to save that bar. At a later moment, whenever you choose to, you may retrueve that value and compare it to the caurrent BARINDEX to know exactly how many bars have elapsed.

    This is an example saving the bar number when an average crossing happens and computes the number of bars elapsed from then to the next crossing:

    ONCE EventBar = 0
    a = Average[20](close)
    b = Average[100](close)
    IF (a CROSSES OVER b) OR (a CROSSES UNDER b) THEN //in case of any crossing
       x = BARINDEX - EventBar                        //x will tell you how many bars have elapsed since the previous crossing
       EventBar = BARINDEX                            //make it ready for the next count
    ENDIF

    Roberto

    #55501 quote
    ck1066
    Participant
    Average

    Thanks Roberto, BARINDEX is exactly what I’m looking for.

    #170083 quote
    IG_CFD_Trader
    Participant
    Average
    Hi Roberto, I have the highest high during intraday being drawn on current bar. If for example the highest high bar occurred x bars ago and that particular bar had another value drawn on it by an indicator. How do I make reference to that highest high bar (x bars ago) and have the code also show on current bar the value of the indicator on that x bar?
    #170091 quote
    robertogozzi
    Moderator
    Master
    @IG_CFD_Trader Do not double post. You opened another topic. Thank you 🙂
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Number of bars between two reference points


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
ck1066 @ck1066 Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by robertogozzi
4 years, 8 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/12/2017
Status: Active
Attachments: No files
Logo Logo
Loading...