This indicator draws three average lines. The green line is the average value of the last p swing high fractals and the red line is the average value of the last p swing low fractals. The blue line is the mid point between these two averages.
This indicator only works on PRTv11 onwards.
Set the period used for the average calculation by changing the value of p.
The type of fractal used in the calculation can be changed by adjusting the ‘BarsBefore’ and ‘Bars After’ settings. For example if BarsBefore = 2 and BarsAfter = 1 then the swing high fractals would have a high with two bars preceding it with lower highs and one bar after it with a lower high and the swing low fractals would have a low with two bars preceding it with higher lows and one bar after it with a higher low.
The displaying of the three lines can be turned on or off using the ‘HighFracAverage’, ‘LowFracAverage’ and ‘MidAverage’ settings.
As always I advise downloading and importing the ITF file to get full functionality.
//Fractals Average
//By Vonasi
//Date 20200406
p = 50
BarsBefore = 2
BarsAfter = 2
Support = 1
Resistance = 1
once supportavg = undefined
once resistanceavg = undefined
if barindex >= barsbefore + barsafter then
BarsBefore = max(BarsBefore,1)
BarsBefore = max(BarsAfter,1)
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 support then
supporttotal = 0
if a >= p then
for c = a downto a-p+1
supporttotal = supporttotal+$supportvalue[c]
next
supportavg = supporttotal/p
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
if resistance then
resistancetotal = 0
if b >= p then
for c = b downto b-p+1
resistancetotal = resistancetotal+$resistancevalue[c]
next
resistanceavg = resistancetotal/p
endif
endif
endif
midavg = ((supportavg + resistanceavg)/2)
if not highfracaverage then
resistanceavg = undefined
endif
if not lowfracaverage then
supportavg = undefined
endif
if not midaverage then
midavg = undefined
endif
return supportavg coloured(128,0,0), resistanceavg coloured(0,128,0), midavg coloured(0,0,255)