https://www.tradingview.com/script/OrlG ... -lb-alert/
- Code: Select all
//
// @author opafce
//
study(shorttitle = "div_sq_lb_alert", title="Squeeze Momentum Indicator [LazyBear]", overlay=false)
length = input(20, title="BB Length")
mult = input(2.0,title="BB MultFactor")
lengthKC=input(20, title="KC Length")
multKC = input(1.5, title="KC MultFactor")
useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)
// Calculate BB
source = close
basis = sma(source, length)
dev = multKC * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
// Calculate KC
ma = sma(source, lengthKC)
range = useTrueRange ? tr : (high - low)
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz = (sqzOn == false) and (sqzOff == false)
val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)),
lengthKC,0)
bcolor = iff( val > 0,
iff( val > nz(val[1]), lime, green),
iff( val < nz(val[1]), red, maroon))
scolor = noSqz ? blue : sqzOn ? black : gray
//plot(val, color=bcolor, style=histogram, linewidth=4)
//plot(0, color=scolor, style=cross, linewidth=2)
local_ex_up=iff(val>0 and val<val[1] and val[1]>val[2],val,local_ex_up[1])
//plot (local_ex_up)
close_local_up=iff(val>0 and val<val[1] and val[1]>val[2],close,close_local_up[1])
//local_ex_up2=
//close_local_up2=
local_ex_dn=iff(val<0 and val>val[1] and val[1]<val[2],val,local_ex_dn[1])
//plot (local_ex_dn)
close_local_dn=iff(val<0 and val>val[1] and val[1]<val[2],close,close_local_dn[1])
dn_sg=(close_local_up>close_local_up[1] and local_ex_up[1]>local_ex_up)
dn_sg_custom= (close_local_dn>close_local_dn[1] and local_ex_dn[1]>local_ex_dn)
up_sg= (close_local_dn<close_local_dn[1] and local_ex_dn[1]<local_ex_dn)
up_sg_custom=(close_local_up<close_local_up[1] and local_ex_up[1]<local_ex_up)
//plotchar(dn_sg, char='d',color=red)
//plotchar(up_sg, char='d',color=green,location=location.belowbar)
//plotchar(dn_sg_custom, char='d',color=maroon)
//plotchar(up_sg_custom,char='d' ,color=olive,location=location.belowbar)
//bgcolor(up_sg ? green: na, transp=75)
//bgcolor(dn_sg ? red : na, transp=75)
//bgcolor(up_sg_custom ? olive: na, transp=75)
//bgcolor(dn_sg_custom ? maroon : na, transp=75)
//plot(close_local_up)
//plot(close_local_dn,color=red)
a = (dn_sg or dn_sg_custom or up_sg or up_sg_custom) ? (2) : (0)
plot(a, color=orange, linewidth = 4, title = "signal")
plot(1, linewidth = 4, title ="static")