CryptoRox

Squeeze Momentum Alert Script

1197
This is the alert script for the squeeze momentum strategy found here...

Long on Green,
Short on Red,
Close Longs on Aqua,
Close Shorts on Orange.

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//original indicator created by LazyBear
//https://www.tradingview.com/script/nqQ1DT5a-Squeeze-Momentum-Indicator-LazyBear/
//
//Automate this strategy using the AutoView Chrome Extension
//https://chrome.google.com/webstore/detail/autoview/okdhadoplaoehmeldlpakhpekjcpljmb?hl=en
study(title="Sqz-Study-BTC", shorttitle = "Alerts", overlay=false)

length = input(27, title="BB Length")
mult = input(2.0,title="BB MultFactor")
lengthKC=input(19, 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)

goTime = sqzOn[1] == 1 and sqzOff == 1 or noSqz[1] == 1 and sqzOff == 1 ? 1:0

long = goTime == 1 and val > 0 and val > nz(val[1])
short = goTime == 1 and val < 0 and val < nz(val[1])

cl = val < nz(val[1]) and val[1] < nz(val[2]) ? 1:0
cs = val > nz(val[1]) and val[1] > nz(val[2]) ? 1:0

closelong = crossover(cl, 0.9)
closeshort = crossover(cs, 0.9)

plot(long, "Long", color=green)
plot(short, "Short", color=red)
plot(closelong, "CloseLong", color=aqua)
plot(closeshort, "CloseShort", color=orange)