本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=2
//All credit to https://www.tradingview.com/script/YQrMdIka-UCS-Squeeze-Momentum-Optimized-Overlay/
//I just changed the visuals and added alerts when price is released from the squeeze. I find it works
//well on lower timeframes for Forex and Bitcoin. Suggestions for other instruments and timeframes are welcome!
//When adding alerts use 'On Condition' to get the fastest alerts - Scarf
//Best used in conjunction with https://www.tradingview.com/script/0JQPULIU-UCS-Squeeze-Optimization/
study(title = "UCS Squeeze Momentum Overlay with Alerts", overlay=true)
length = input(20, title="Squeeze Length")
multBB = input(2,title="BB MultFactor")
multKC = input(1.5, title="KC MultFactor")
smooth = input(20, title = "Momentum Smoothing")
usebbr = input(true, title = "Use Bollinger Band Ratio Instead of Momentum", type = bool)
useHAC = input(true, title = "Heikin Ashi Optimization", type=bool)
// Heikin Ashi ATR Calculations
haclose = ohlc4
haopen = na(haopen[1]) ? (open + close)/2 : (haopen[1] + haclose[1]) / 2
hahigh = max (high, max(haopen,haclose))
halow = min (low, min(haopen,haclose))
haatra = abs(hahigh - haclose[1])
haatrb = abs(haclose[1] - halow)
haatrc = abs(hahigh - halow)
haatr = max(haatra, max(haatrb,haatrc))
source = useHAC ? haclose : close
// Calculate BB
basis = sma(source, length)
dev = multBB * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
// Calculate KC
ma = sma(source, length)
range = useHAC ? haatr : tr
rangema = sma(range, length)
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)
// Momentum ======> %B Indicator OR Rate of Change (ROC)
momentum = usebbr ? (((source - lowerBB)/(upperBB - lowerBB))-0.5) : (((close - close[12])/close[12])*100)
val = sma(momentum,smooth)
scolor = noSqz ? blue : sqzOn ? red : na
// Background Highlight
bgcolor(scolor)
// Momentum arrows
positiveup = (val > 0) and (val > val[1])
positivedn = (val > 0) and (val < val[1])
negativedn = (val < 0) and (val < val[1])
negativeup = (val < 0) and (val > val[1])
plotshape (positiveup ? positiveup : na, title = "Momentum Positive & Up", style = shape.triangleup, location = location.abovebar, color = green)
plotshape (positivedn ? positivedn : na, title = "Momentum Positive & Down", style = shape.triangledown, location = location.abovebar, color = blue)
plotshape (negativeup ? negativeup : na, title = "Momentum Negative & Up", style = shape.triangleup, location = location.belowbar, color = orange)
plotshape (negativedn ? negativedn : na, title = "Momentum Negative & Down", style = shape.triangledown, location = location.belowbar, color = red)
squeeze_released = not sqzOn and sqzOn[1]
//plot(squeeze_released)
alertcondition(squeeze_released and positiveup or squeeze_released and negativeup, title='Squeeze Released: Long', message='Squeeze Released: Long ')
alertcondition(squeeze_released and negativedn or squeeze_released and positivedn, title='Squeeze Released: Short', message='Squeeze Released: Short ')