The basic algorithm for this indicator is Zig Zag indicator. Each time a new peak or trough is found, the averaged value are inverted:
This indicator was coded by a request in the English indicators forum.
//PRC_ZigZag Average | indicator
//30.05.2018
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//--- settings
Percentage = 1
mmPeriod = 30
//--- end of settings
peak = ZigZag[Percentage](high)
trough = ZigZag[Percentage](low)
if peak<peak[1] and peak[1]>peak[2] then
last=1
endif
if trough>trough[1] and trough[1]<trough[2] then
last=-1
endif
if last>0 then
mm=average[mmPeriod](high)
else
mm=average[mmPeriod](low)
endif
if mm>mm[1] then
r=0
g=128
b=196
else
r=255
g=0
b=0
endif
return mm coloured(r,g,b) style(line,2)