// Fractls
//
// https://www.prorealcode.com/topic/distance-to-last-fractal-high/
//
ONCE P = 15
ONCE HH = 0
ONCE HHprev = 0
ONCE LL = 0
ONCE LLprev = 0
ONCE LastFractal = 0
FractalDistance = 0
Offset = average[20,0](range)
Bullish = close > open
Bearish = close < open
HIGHfractal = Bullish[1] AND Bearish AND (high[1] > high[2]) AND (high[1] > high) AND (high[1] = highest[P](high))
LOWfractal = Bearish[1] AND Bullish AND (low[1] < low[2]) AND (low[1] < low) AND (low[1] = lowest[P](low))
//
IF HIGHfractal AND ((LastFractal = 0) OR (LastFractal = -1)) THEN
LastFractal = 1
HHprev = HH
HH = high[1]
DrawText("●",BarIndex[1],high[1] + Offset,dialog,standard,15) coloured("Green")
IF HHprev <> 0 THEN
Gap = HH - HHprev
DrawText("#Gap#",BarIndex[1],high[1] + Offset*2,dialog,standard,15) coloured("Green")
ENDIF
ENDIF
//
IF LOWfractal AND ((LastFractal = 0) OR (LastFractal = 1)) THEN
LastFractal = -1
LLprev = LL
LL = low[1]
DrawText("●",BarIndex[1],low[1] - Offset,dialog,standard,15) coloured("Red")
IF LLprev <> 0 THEN
Gap = LLprev - LL
DrawText("#Gap#",BarIndex[1],low[1] - Offset*2,dialog,standard,15) coloured("Red")
ENDIF
ENDIF
//
RETURN