Finding last two Fractals position

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #39154 quote
    bmentink
    Participant
    Average

    Hi Guys,

    I am trying to write some code to find the time (index) when the last two low Fractals occurred, or the last two High Fractals occurred.

    I want to use their positional information to calculate Fractal divergence against an indicator.

    I am struggling as the normal Fractal code uses the “lowest” function which works for the last Fractal, but does not allow an offset to find the 2nd to last Fractal.

    Any help much appreciated.

    B.

    #39222 quote
    Nicolas
    Keymaster
    Master

    You can make a new variable that store the previous high fractal barindex if a new high one is found. This way, you should be able to compare the current fractal barindex to the previous one stored in a variable.

    #39248 quote
    bmentink
    Participant
    Average

    Thanks Nicolas,

    I am having trouble with how to store the previous Fractal, in the code snippet (just the low Fractal):

    cp = 2 //(default)
    
    PreviousLF = -1
    
    if low[cp] <= lowest[2*cp+1](low)  then
    CurrentLF = barindex
    else
    CurrentLF = -1
    endif
    

    I don’t know how/when to save the CurrentLF to PreviousLF

    Cheers

    #39279 quote
    Nicolas
    Keymaster
    Master

    You could do it this way instead:

    cp = 2 //(default)
    
    if low[cp] <= lowest[2*cp+1](low)  then
     PreviousLF = CurrentLF
     CurrentLF = barindex
    endif

    So now you have continuously a set of 2 low fractals barindex stored.

    #39337 quote
    bmentink
    Participant
    Average

    Thanks Nicolas, wasn’t thinking 😉

    #147345 quote
    Monochrome
    Participant
    Senior

    Hi im trying to find the values of the previous THREE factals. Having trouble.

    cp = 20
    if high[cp] >= highest[2*cp+1](high) then
    pprevioushf = PrevioushF
    PrevioushF = CurrentHF
    CurrentHF = barindex
    endif
     
    if low[cp] <= lowest[2*cp+1](low)  then
    ppreviouslf = PreviousLF
    PreviousLF = CurrentLF
    CurrentLF = barindex
    endif
    
    TOPy = high[currenthf]
    TOPy1 = high[previoushF]
    TOPy2 = high[pprevioushF]
    BOTy = low[currentLF]
    BOTy1 = low[previousLF]
    BOTy2 = low[ppreviouslf

    Can somebody help me?

    #147351 quote
    robertogozzi
    Moderator
    Master

    This Nicolas’code modified to accomodate for another two places:

    if low[cp] <= lowest[2*cp+1](low)  then
     Previous3LF = Previous2LF
     Previous2LF = Previous1LF
     Previous1LF = CurrentLF
     CurrentLF   = barindex
    endif

    so you can now access Previous1LF, Previous2LF and Previous3LF.

    Monochrome thanked this post
    #147353 quote
    Monochrome
    Participant
    Senior

    Thankyou for your reply.

    If i want to find the value(high or low) of a previous factal such as ‘previous3LF’, is this code correct?

    Top3 = high[previous3LF]
    #147356 quote
    robertogozzi
    Moderator
    Master

    No, you should write:

    Top3 = high[BarIndex - previous3LF]

    Because if now it’s BarIndex 100 and previous3LF is 81, then you have to access the 19th previous bar to get the correct value.

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

Finding last two Fractals position


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
bmentink @bmentink Participant
Summary

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

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