//Fractals Average
//By Vonasi
//Date 20200402
//p = 50
//BarsBefore = 2
//BarsAfter = 2
once supportavg = undefined
once resistanceavg = undefined
BarsBefore = max(BarsBefore,1)
BarsBefore = max(BarsAfter,1)
if barindex >= barsbefore + barsafter then
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 high[BarsAfter] > highest[BarsBefore](high)[BarLookBack] THEN
if high[BarsAfter] = highest[BarLookBack](high) THEN
b = b + 1
$resistancevalue[b] = high[barsafter]
endif
endif
supporttotal = 0
if a >= p then
for c = a downto a-p+1
supporttotal = supporttotal+$supportvalue[c]
next
supportavg = supporttotal/p
endif
resistancetotal = 0
if b >= p then
for c = b downto b-p+1
resistancetotal = resistancetotal+$resistancevalue[c]
next
resistanceavg = resistancetotal/p
endif
endif
return supportavg coloured(128,0,0), resistanceavg coloured(0,128,0)