Fractals average using arrays

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #124352 quote
    Vonasi
    Moderator
    Master

    Here is another example showing the benefits of the arrays that are now available in PRTv11.

    This indicator stores the value of every fractal (swing high and swing low) so that we can then calculate any period average of them that we like. So a 10 period average would look at the last ten swing highs and add them up and divide by 10 and the same for swing lows.

    Add it to the price chart.

    The type of fractal can be selected by changing the ‘BarsBefore’ and ‘BarsAfter’ values and period for the average set by changing the ‘p’ value.

    The attached image shows 3 bar fractal 50 period averages on the EURUSD daily.

    //Fractals Average
    //By Vonasi
    //Date 20200402
    
    //p = 50
    //BarsBefore = 2
    //BarsAfter = 2
    
    once supportavg = undefined
    once resistanceavg = undefined
    
    BarsBefore = max(BarsBefore,1)
    BarsBefore = max(BarsAfter,1)
    
    if barindex >= barsbefore + barsafter then
    BarLookBack = BarsAfter + 1
    if low[BarsAfter] < lowest[BarsBefore](low)[BarLookBack] THEN
    if low[BarsAfter] = lowest[BarLookBack](low) THEN
    a = a + 1
    $supportvalue[a] = low[barsafter]
    endif
    endif
    if high[BarsAfter] > highest[BarsBefore](high)[BarLookBack] THEN
    if high[BarsAfter] = highest[BarLookBack](high) THEN
    b = b + 1
    $resistancevalue[b] = high[barsafter]
    endif
    endif
    
    supporttotal = 0
    if a >= p then
    for c = a downto a-p+1
    supporttotal =  supporttotal+$supportvalue[c]
    next
    supportavg = supporttotal/p
    endif
    
    resistancetotal = 0
    if b >= p then
    for c = b downto b-p+1
    resistancetotal =  resistancetotal+$resistancevalue[c]
    next
    resistanceavg = resistancetotal/p
    endif
    endif
    
    return supportavg coloured(128,0,0), resistanceavg coloured(0,128,0)
    GraHal, Nicolas and Ste thanked this post
    #124736 quote
    Rory Dryden
    Participant
    New

    Is there a download file for this?

    #124738 quote
    Vonasi
    Moderator
    Master

    I didn’t attach one as really it was just an example exercise in playing with arrays. My platform is shut down at the moment but I’ll add an ITF file tomorrow and maybe even submit it to the library tomorrow. No point in doing that now as it’s Sunday and Nicolas is most likely sleeping off the cocktails he’s been drinking in the garden all afternoon!

    You can always copy and paste the code above into a new indicator with creation by programming and then add ‘p’ and ‘BarsBefore’ and ‘BarsAfter’ as a changeable variables or just remove the // before them in the code.

    #124749 quote
    Vonasi
    Moderator
    Master

    You can now find this indicator in the library:

    Fractals Average

    I’ve also added a blue mid line that is the average position of the swing high fractal line and the swing low fractal line. You can turn the display of any of the three lines on and off by ticking the relevant box.

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

Fractals average using arrays


ProBuilder support

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Vonasi
5 years, 10 months ago.

Topic Details
Forum: ProBuilder support
Language: English
Started: 04/02/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...