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.
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
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.
A falling ADX is current ADX < previous ADX.
The falling is even stronger the more periods you account for ADX < previous one!
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.
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, ..