CryptoRox

Squeeze Momentum Alert Script

1198
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.

Script de código aberto

Dentro do verdadeiro espírito TradingView, o autor deste script publicou ele como um script de código aberto, para que os traders possam compreender e checar ele. Um viva ao autor! Você pode usá-lo gratuitamente, mas a reutilização deste código em uma publicação é regida pelas Regras da Casa. Você pode favoritá-lo para usá-lo em um gráfico.

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.

Quer usar esse script no gráfico?
//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)