Peak Valley

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #101028 quote
    Dr Manhattan
    Participant
    Senior

    Hi, I have seached forums for “Peak” / “Valley” functions but not exactly found what Im looking for.

    Im looking for a method / function to identify peaks / valleys which are not so pointy. For example using a moving average with 500 on a price curve generates this type of slow peaks / valleys. The functions I have found in the forum doesnt find these peaks / valleys.

    Any idea what type of code I could use to identify those ones. They often have a few bars of a horizontal line in the middle.

    #101032 quote
    robertogozzi
    Moderator
    Master

    Yes, a PEAK is when your average is the highest within a range of bars, VALLEY is when it’s the lowest.

    DEFPARAM CalculateOnLastBars = 3000
    p        = 500
    LookBack = 500
    MyAvg    = average[p,0](close)
    Valley   = lowest[LookBack](MyAvg)
    Peak     = highest[LookBack](MyAvg)
    x = 0
    IF MyAvg = Peak THEN
       x = 1
    ELSIF MyAvg = Valley THEN
       x = -1
    ENDIF
    RETURN x,0
    x-12.jpg x-12.jpg
    #101077 quote
    Dr Manhattan
    Participant
    Senior

    Thanks! Thats a good definition of PEAK / VALLEY.

    I have another question, it might not be on the same topic but related how would you define or try to measure falling, for example a falling ADX.

    #101080 quote
    robertogozzi
    Moderator
    Master

    A falling ADX is current ADX < previous ADX.

    The falling is even stronger the more periods you account for ADX < previous one!

    #101083 quote
    robertogozzi
    Moderator
    Master

    Examples:

    Periods  = 14                 //14  ADX periods
    LookBack = 3                  //3   consecutive falling ADX periods
    MyAdx = Adx[Periods]
    IF summation[LookBack](MyAdx < MyAdx[1]) = LookBack THEN
       //actions to be taken when ADX is falling for 3 LOOKBACK consecutive periods
    ENDIF

    you need to replace MyAdx < MyAdx[1] with MyAdx > MyAdx[1] for a rising ADX.

    Dr Manhattan thanked this post
    #101090 quote
    Nicolas
    Keymaster
    Master

    As for peak and valley, you can also use any type of highest high / lowest low detection such as zigzag, fractals, swing hi/lo, donchian channel, ..

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

Peak Valley


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

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

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 06/19/2019
Status: Active
Attachments: 1 files
Logo Logo
Loading...