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.

开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?
//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)