LNL Squeeze Arrows
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//
// @version=5
//
// L&L Squeeze Arrows
//
// Squeeze Arrows pinpoint the exact moment where the squeeze momentum change happens (momentum change is CRUCIAL for the squeeze setup)
//
// Two types of arrows: 1.Squezee Arrows - showing the best entries for this setup.  2.Slingshot Arrows - showing the current direction of the squeeze (caution / confirmation tool)
//
// If an opposite arrow is plotted = stay away from the trade & wait for the true momentum change (Last Arrow is the valid signal)
//
// Created by © L&L Capital
// 

indicator("LNL Squeeze Arrows",shorttitle="Squeeze Arrows", overlay=true) 


// Inputs

length = 20
SqueezeCount = input(defval = 5,title='Squeze Dots Trigger')


// Squeeze Calculations

BB_mult = 2.0
BB_basis = ta.sma(close, length)
dev = BB_mult * ta.stdev(close, length)
BB_upper = BB_basis + dev
BB_lower = BB_basis - dev
KC_mult_high = 1.0
KC_mult_mid = 1.5
KC_mult_low = 2.0
KC_basis = ta.sma(close, length)
devKC = ta.sma(ta.tr, length)
KC_upper_high = KC_basis + devKC * KC_mult_high
KC_lower_high = KC_basis - devKC * KC_mult_high
KC_upper_mid = KC_basis + devKC * KC_mult_mid
KC_lower_mid = KC_basis - devKC * KC_mult_mid
KC_upper_low = KC_basis + devKC * KC_mult_low
KC_lower_low = KC_basis - devKC * KC_mult_low
NoSqz = BB_lower < KC_lower_low or BB_upper > KC_upper_low 
//LowSqz = BB_lower >= KC_lower_low or BB_upper <= KC_upper_low 
MidSqz = BB_lower >= KC_lower_mid or BB_upper <= KC_upper_mid 
//HighSqz = BB_lower >= KC_lower_high or BB_upper <= KC_upper_high 
SqzOff = BB_lower < KC_lower_mid and BB_upper > KC_upper_mid 


// Squeeze Histogram Calculations 

momo = ta.linreg(close - math.avg(math.avg(ta.highest(high, length), ta.lowest(low, length)), ta.sma(close, length)), length, 0)
iff_1 = momo > 0 and  momo > nz(momo[1])  // Histogram Pos & Up
iff_2 = momo < 0 and momo < nz(momo[1])   // Histogram Neg & Dn 
momo_color = momo > 0 ? iff_1 : iff_2
HistogramUp = iff_1
HistogramDn = iff_2


// Arrows Calculations

GreenCandle = close > open
RedCandle = close < open

ema8 = ta.ema(close, 8)
ema21 = ta.ema(close, 24)
ema34 = ta.ema(close, 34)
ema55 = ta.ema(close, 55)
StackedEMAsUp = ema8 > ema21 and ema34 > ema55
StackedEMAsDn = ema8 < ema21 and ema34 < ema55 


// Squeeze Trigger Calculations    

normal = 0.0
normal := nz(normal[1])
if (SqzOff)
    normal := 0
else
    if (MidSqz)
        normal := normal + 1  

SqueezeTrigger = (normal >= SqueezeCount)


// Fisher Shift Arrows

flength = 5
high_ = ta.highest(hl2, flength)
low_ = ta.lowest(hl2, flength)
round_(val) => val > .99 ? .999 : val < -.99 ? -.999 : val
value = 0.0
value := round_(.66 * ((hl2 - low_) / math.max(high_ - low_, .001) - .5) + .67 * nz(value[1]))
fish1 = 0.0
fish1 := .5 * math.log((1 + value) / math.max(1 - value, .001)) + .5 * nz(fish1[1])
fish2 = fish1[1]
FisherUp =ta.crossover(fish1,fish2) and fish1 < 0
FisherDn = ta.crossunder(fish1,fish2) and fish1 > 0 

// Plots

// Squeeze Arrow Up
SqueezeSignalUp = MidSqz and GreenCandle and HistogramUp and StackedEMAsUp and SqueezeTrigger
plotshape(SqueezeSignalUp,title='Squeeze Up',style=shape.triangleup,location=location.belowbar,color=(color.aqua),size=size.small)    

// Squeeze Arrow Down
SqueezeSignalDn = MidSqz and RedCandle and HistogramDn and StackedEMAsDn and SqueezeTrigger
plotshape(SqueezeSignalDn,title='Squeeze Down',style=shape.triangledown,location=location.abovebar,color=(#cc0000),size=size.small)  

// Slingshot Arrow Up
SlingshotSignalUp = MidSqz and momo > 0 and momo[1] > 0 and momo[2] < 0 
plotshape(SlingshotSignalUp,title='Slingshot Up',style=shape.triangleup,location=location.belowbar,color=(color.yellow),size=size.small) 

// Slingshot Arrow Dn
SlingshotSignalDn = MidSqz and momo < 0 and momo[1] < 0 and momo[2] > 0 
plotshape(SlingshotSignalDn,title='Slingshot Down',style=shape.triangledown,location=location.abovebar,color=(color.yellow),size=size.small) 

// Fisher Shift Signal Up
ShiftSignalUp =  MidSqz[15] and NoSqz and momo < 0 and FisherUp
plotshape(ShiftSignalUp,title='Shift Up',style=shape.triangleup,location=location.belowbar,color=(color.purple),size=size.tiny) 

// Fisher Shift Signal Dn
ShiftSignalDn =  MidSqz[15] and NoSqz and momo > 0 and FisherDn
plotshape(ShiftSignalDn,title='Shift Down',style=shape.triangledown,location=location.abovebar,color=(color.purple),size=size.tiny) 

