//Defparam calculateonlastbars = 5000
// --- settings
//ATRNumberHeight=10
//FractalShoulderSize=14
// --- end of settings
once SwingLow=0
once SwingLow2=0
once SwingLow3=0
once SwingHigh=0
once SwingHigh2=0
once SwingHigh3=0
once i=0
once j=0
once k=0
once lownext=1
once highnext=0
R = FractalShoulderSize //Fractal Shoulder Size
//Adjusts distance of numbers above candles relative to timeframe
atr = AverageTrueRange[ATRNumberHeight](close)[R]/pipsize
//Identify the 1st swing low
if not swinglow and lownext then
IF low[R] < lowest[R](low) and low[R] < lowest[R](low)[R+1] Then
SwingLow = low[R] //(R lower lows on left and R lower lows on right)
Endif
elsif swinglow>0 then
i=i+1
IF i=1 or i=9 or i=17 or i=26 or i=33 or i=42 or i=65 or i=76 or i=129 or i=172 or i=257 then
drawtext("#i#",barindex-R+1,low[R+1]-(pipsize*ATR*4)) coloured(255,0,0)
If i=172 or i=257 Then
DRAWARROWUP(barindex-R+1,low[R+1]-(pipsize*ATR*2)) coloured(255,0,0)
EndIf
endif
if i=257 then //65 42
SwingLow=0
i=0
lownext=0
highnext=1
endif
IF i>1 and not SwingLow2 and low[R] < lowest[R](low) and low[R] < lowest[R](low)[R+1] Then
SwingLow2 = low[R] //(R lower lows on left and R lower lows on right)
Elsif SwingLow>0 and SwingLow2>0 and not Swinglow3 then
IF low[R] < lowest[R](low) and low[R] < lowest[R](low)[R+1] Then
SwingLow3 = low[R] //(R lower lows on left and R lower lows on right)
Endif
endif
endif
if Swinglow2>0 then
j=j+1
IF j=1 or j=9 or j=17 or j=26 or j=33 or j=42 or j=65 or j=76 or j=129 or j=172 or j=257 then
drawtext("#j#",barindex-4,low[R]-(pipsize*ATR*4)) coloured(0,255,0)
If j=172 or j=257 Then
DRAWARROWUP(barindex-R,low[R]-(pipsize*ATR*2)) coloured(0,255,0)
EndIf
endif
if j=257 then //65 42
SwingLow2=0
j=0
endif
endif
if Swinglow3>0 then
k=k+1
IF k=1 or k=9 or k=17 or k=26 or k=33 or k=42 or k=65 or k=76 or k=129 or k=172 or k=257 then
drawtext("#k#",barindex-R,low[R]-(pipsize*ATR*4)) coloured(0,0,255)
If k=172 or k=257 Then
DRAWARROWUP(barindex-R,low[R]-(pipsize*ATR*2)) coloured(0,0,255)
EndIf
endif
if k=257 then //65 42
SwingLow3=0
k=0
endif
endif
//Identify the 1st swing high
if not swinghigh and highnext then
If high[R] > highest[R](high) and high[R] > highest[R](high)[R+1] Then
SwingHigh = high[R] //(R lower highs on left and R lower highs on right)
Endif
elsif swinghigh>0 then
i=i+1
IF i=1 or i=9 or i=17 or i=26 or i=33 or i=42 or i=65 or i=76 or i=129 or i=172 or i=257 then
drawtext("#i#",barindex-R+1,high[R+1]+(pipsize*ATR*4)) coloured(255,0,0)
If i=172 or i=257 Then
DRAWARROWDOWN(barindex-R+1,high[R+1]+(pipsize*ATR*2)) coloured(255,0,0)
EndIf
endif
if i=257 then //65 42
Swinghigh=0
i=0
highnext=0
lownext=1
endif
If i>1 and not SwingHigh2 and high[R] > highest[R](high) and high[R] > highest[R](high)[R+1] Then
SwingHigh2 = high[R] //(R lower highs on left and R lower highs on right)
Elsif Swinghigh>0 and Swinghigh2>0 and not SwingHigh3 then
If high[R] > highest[R](high) and high[R] > highest[R](high)[R+1] Then
SwingHigh3 = high[R] //(R lower highs on left and R lower highs on right)
Endif
endif
endif
if Swinghigh2>0 then
j=j+1
IF j=1 or j=9 or j=17 or j=26 or j=33 or j=42 or j=65 or j=76 or j=129 or j=172 or j=257 then
drawtext("#j#",barindex-R,high[R]+(pipsize*ATR*4)) coloured(0,255,0)
If j=172 or j=257 Then
DRAWARROWDOWN(barindex-R,high[R]+(pipsize*ATR*2)) coloured(0,255,0)
EndIf
endif
if j=257 then //65 42
Swinghigh2=0
j=0
endif
endif
if Swinghigh3>0 then
k=k+1
IF k=1 or k=9 or k=17 or k=26 or k=33 or k=42 or k=65 or k=76 or k=129 or k=172 or k=257 then
drawtext("#k#",barindex-R,high[R]+(pipsize*ATR*4)) coloured(0,0,255)
If k=172 or k=257 Then
DRAWARROWDOWN(barindex-R,high[R]+(pipsize*ATR*2)) coloured(0,0,255)
EndIf
endif
if k=257 then //65 42
Swinghigh3=0
k=0
endif
endif
return