本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OskarGallard
//@version=4
study(shorttitle="SQZMOM [+]", title="Squeeze Momentum [Plus]", overlay=false)
//_________________________________________________________________________________
// Based on "Squeeze Momentum Indicator" - Author:@LazyBear and @J-Streak
// https://www.tradingview.com/script/nqQ1DT5a-Squeeze-Momentum-Indicator-LazyBear/
// https://www.tradingview.com/script/557GijRq-JS-Squeeze-Pro-2/
//_________________________________________________________________________________
show_Momen = input(true, title="═════════ Show Momentum ═════════")
//----------------------------{ Inputs }----------------------------------------
src = input(close, title="Squeeze Input", type=input.source)
int length = input(20, title="Length", minval=1, step=1)
string bbmatype = input('SMA', title='Bollinger Bands Calculation Type', options=["SMA", "EMA", "WMA", "LSMA", "ALMA", "HMA", "KAMA", "RMA", "DEMA", "TEMA", "VWMA", "SWMA"])
string kcmatype = input('SMA', title='Keltner Channel Calculation Type', options=["SMA", "EMA", "WMA", "LSMA", "ALMA", "HMA", "KAMA", "RMA", "DEMA", "TEMA", "VWMA", "SWMA"])
int color_1 = input(3, title="Color Format", minval=1, maxval=5)
bool drdiv = input(false, title="Draw Divergence")
bool bgoff = input(false, title="Background Off")
bool darkm = input(false, title="Gray Background for Dark Mode")
bool zerold = input(false, title="Zero Line")
// Kaufman's Adaptive Moving Average - Fast and Slow Ends
fastK = 0.666 // KAMA Fast End
slowK = 0.645 // KAMA Slow End
kama(x, t)=>
dist = abs(x[0] - x[1])
signal = abs(x - x[t])
noise = sum(dist, t)
effr = noise!=0 ? signal/noise : 1
sc = pow(effr*(fastK - slowK) + slowK,2)
kama = x
kama := nz(kama[1]) + sc*(x - nz(kama[1]))
kama
ma(MAType, MASource, MAPeriod) =>
if MAPeriod > 0
if MAType == "SMA"
sma(MASource, MAPeriod)
else if MAType == "LSMA"
linreg(MASource, MAPeriod, 0)
else if MAType == "EMA"
ema(MASource, MAPeriod)
else if MAType == "WMA"
wma(MASource, MAPeriod)
else if MAType == "RMA"
rma(MASource, MAPeriod)
else if MAType == "HMA"
hma(MASource, MAPeriod)
else if MAType == "DEMA"
e = ema(MASource, MAPeriod)
2 * e - ema(e, MAPeriod)
else if MAType == "TEMA"
e = ema(MASource, MAPeriod)
3 * (e - ema(e, MAPeriod)) + ema(ema(e, MAPeriod), MAPeriod)
else if MAType == "VWMA"
vwma(MASource, MAPeriod)
else if MAType == "ALMA"
alma(MASource, MAPeriod, 6, .85)
else if MAType == "SWMA"
swma(MASource)
else if MAType == "KAMA"
kama(MASource, MAPeriod)
//Bollinger Bands Basis Line
basis = ma(bbmatype, src, length)
//Keltner Channel Basis Line
basiskc = ma(kcmatype, src, length)
// Keltner Channel Range
range = ma(kcmatype, tr, length)
//Bollinger Bands Multiplier
multBB = 2.0
//Keltner Channel Low Multiplier
multlowKC = 2.0
//Keltner Channel Mid Multiplier
multmidKC = 1.5
//Keltner Channel High Multiplier
multhighKC = 1.0
//Bollinger Bands
dev = multBB * stdev(src, length)
upperBB = basis + dev
lowerBB = basis - dev
//Keltner Channel Bands Low
upperKCl = basiskc + range * multlowKC
lowerKCl = basiskc - range * multlowKC
//Keltner Channel Bands Mid
upperKCm = basiskc + range * multmidKC
lowerKCm = basiskc - range * multmidKC
//Keltner Channel Bands High
upperKCh = basiskc + range * multhighKC
lowerKCh = basiskc - range * multhighKC
//------------------------{ Squeeze Basics }------------------------------------
//Squeeze Momentum
sz = linreg(src - avg(avg(highest(high, length), lowest(low, length)), ema(close, length)), length, 0)
//Squeeze Conditions
sc1 = sz >= 0
sc2 = sz < 0
sc3 = sz >= sz[1]
sc4 = sz < sz[1]
//Squeeze On
lowsqz = lowerBB > lowerKCl and upperBB < upperKCl
lsf = lowsqz == false
midsqz = lowerBB > lowerKCm and upperBB < upperKCm
msf = midsqz == false
highsqz = lowerBB > lowerKCh and upperBB < upperKCh
hsf = highsqz == false
//-----------------------{ Color Components }-----------------------------------
//Color Conditions
clr1 = sc1 and sc3 ? #00eeff :
sc1 and sc4 ? #000eff : sc2 and sc4 ? #ff0000 : sc2 and sc3 ? #ffe500 : color.gray
clr2 = sc1 and sc3 ? #00bcd4 :
sc1 and sc4 ? #0d47a1 : sc2 and sc4 ? #ba68c8 : sc2 and sc3 ? #9c27b0 : #673ab7
clr3 = sc1 and sc3 ? #15ff00 : sc1 and sc4 ? #388e3c :
sc2 and sc4 ? #f44336 : sc2 and sc3 ? #b71c1c : color.gray
clr4 = sc1 and sc3 ? #fff59d :
sc1 and sc4 ? #ffd600 : sc2 and sc4 ? #ffcc80 : sc2 and sc3 ? #ff9800 : #702700
clr5 = sc1 and sc3 ? #2196f3 :
sc1 and sc4 ? #0d47a1 : sc2 and sc4 ? #ef9a9a : sc2 and sc3 ? #d32f2f : #ce93d8
choice = color_1 == 1 ? clr1 : color_1 == 2 ? clr2 :
color_1 == 3 ? clr3 : color_1 == 4 ? clr4 : color_1 == 5 ? clr5 : na
//Background Conditions
bg1 = color.gray
bg2 = #673ab7
bg3 = color.gray
bg4 = #ffd600
bg5 = #ce93d8
bg6 = #ffb74d
bgc = bgoff ? na : color_1 == 1 ? bg1 : color_1 == 2 ? bg2 :
color_1 == 3 ? bg3 : color_1 == 4 ? bg4 : color_1 == 5 ? bg5 : color_1 == 6 ? bg6 : na
//Background Colors
bgcolor(color=darkm ? bgc : na, editable=false, transp=95)
bgcolor(bgoff ? na : choice)
//Squeeze Dot Colors
orange_red = #FF4000 // Original Squeeze
golden_yellow = #FFE500 // High Squeeze
sqzproc = highsqz ? golden_yellow : midsqz ? orange_red : lowsqz ? color.gray : na
//-----------------{ Indicator Components and Plots }---------------------------
//Squeeze Dot Plot Above
sqzpro = zerold ? na : highsqz ? highsqz : midsqz ? midsqz : lowsqz ? lowsqz : na
plotshape(sqzpro, title="Squeeze Dots Top", style=shape.circle, location=location.top, color=sqzproc, transp=5)
//Plot Zero Line
color_zero = highsqz ? golden_yellow : midsqz ? orange_red : lowsqz ? color.gray : clr3
plot(zerold ? 0 : na, title="Zero Line Squeeze", color=color_zero, linewidth=2, style=plot.style_circles, transp=0)
//Squeeze Plot
plot(show_Momen ? sz : na, title="Squeeze Momentum", color=choice, style=plot.style_histogram, linewidth=3)
//Divergence Formula {Compliments of Ricardo Santos}
ftf(_src) =>
_src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and
_src[2] > _src[0]
fbf(_src) =>
_src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and
_src[2] < _src[0]
ffract(_src) =>
fbf__1 = fbf(_src)
ftf(_src) ? 1 : fbf__1 ? -1 : 0
fractaltop = ffract(sz) > 0 ? sz[2] : na
fractalbot = ffract(sz) < 0 ? sz[2] : na
high_prev = valuewhen(fractaltop, sz[2], 1)
high_price = valuewhen(fractaltop, high[2], 1)
low_prev = valuewhen(fractalbot, sz[2], 1)
low_price = valuewhen(fractalbot, low[2], 1)
regbeardiv = fractaltop and high[2] > high_price and sz[2] < high_prev
hidbeardiv = fractaltop and high[2] < high_price and sz[2] > high_prev
regbulldiv = fractalbot and low[2] < low_price and sz[2] > low_prev
hidbulldiv = fractalbot and low[2] > low_price and sz[2] < low_prev
//Divergence Plot
plot(title='Bearish Fractal', series=drdiv ? fractaltop ? sz[2] : na : na, color=regbeardiv ? choice : na, linewidth=2, offset=-2, editable=false)
plot(title='Bullish Fractal', series=drdiv ? fractalbot ? sz[2] : na : na, color=regbulldiv ? choice : na, linewidth=2, offset=-2, editable=false)
plot(title='Bearish Divergence', series=drdiv ? fractaltop ? sz[2] : na : na, style=plot.style_circles, color=regbeardiv ? choice : na, linewidth=3, offset=-2, editable=false)
plot(title='Bullish Divergence', series=drdiv ? fractalbot ? sz[2] : na : na, style=plot.style_circles, color=regbulldiv ? choice : na, linewidth=3, offset=-2, editable=false)
//______________________________________________________________________________
// Based on "Directional Movement Index and ADX"
// https://www.tradingview.com/script/VroqhJmg/
//______________________________________________________________________________
show_ADX = input(false, title = "═════════ Show ADX ═════════")
scale = input(25.0, title = "Scala for ADX")
adxlen = input(14, title = "ADX Smoothing")
dilen = input(14, title = "DI Length")
keyLevel = input(23, title = "Key level for ADX")
keyColor = input(false, title = "Color DMI for key level")
[diplus, diminus, adxValue] = dmi(dilen, adxlen)
biggest(series) =>
max = 0.0
max := nz(max[1], series)
if series > max
max := series
max
// Calculate ADX Scale
ni = biggest(sz)
adx_scale = (adxValue - keyLevel) * ni/scale
color_ADX = adxValue > adxValue[1] ? color.white : color.gray
color_DMI = diplus >= diminus ? #8080FF : #FF8080
p1 = plot(show_ADX ? adx_scale : na, color = color_ADX, title = "ADX", linewidth = 2)
p2 = plot(show_ADX ? 0 : na, color = keyColor ? color_DMI : color.white, title = "Key Level", linewidth = 1, style = plot.style_circles)
fill(p1, p2, color = color_ADX, title = "DMI Fill")
//_____________________________________________________________________________________
// Hull Moving Average
//_____________________________________________________________________________________
show_Hull = input(true, title = "═════════ Show Hull Signal ═════════")
h_Length = input(55, title="Length", minval=1, step=1, inline = "hull")
h_type = input("HMA", title="Hull Type", options=["HMA", "EHMA", "THMA"], inline = "hull")
// EHMA
EHMA(_src, _length) => ema((2 * ema(_src, _length / 2)) - ema(_src, _length), round(sqrt(_length)))
// THMA
THMA(_src, _length) => wma(wma(_src,_length / 3) * 3 - wma(_src, _length / 2) - wma(_src, _length), _length)
// Hull type
hull_type(type, src, len) =>
type == "Hma" ? hma(src, len) :
type == "Ehma" ? EHMA(src, len) : THMA(src, len/2)
xHMA = hull_type(h_type, close, h_Length)
longHMA = crossover(xHMA[0], xHMA[2])
shortHMA = crossunder(xHMA[0], xHMA[2])
plotshape(show_Hull and longHMA, title="Long Cross", color=color.new(#45CEA2, 10), style=shape.triangleup, location=location.bottom, size=size.tiny, text='H')
plotshape(show_Hull and shortHMA, title="Short Cross", color=color.new(#CE4571, 10), style=shape.triangledown, location=location.top, size=size.tiny, text='H')
//_____________________________________________________________________________________
// Based on "Williams_Vix_Fix_V3_Upper_Text_Plots" - Author: @ChrisMoody
// https://www.tradingview.com/script/1ffumXy5-CM-Williams-Vix-Fix-V3-Upper-Text-Plots/
// https://www.ireallytrade.com/newsletters/VIXFix.pdf
//_____________________________________________________________________________________
show_VF = input(true, title="═════════ Williams Vix Fix ═════════")
// Inputs Tab Criteria
pd = input(22, title="LookBack Period Standard Deviation High")
mult = input(2.0, title="Bollinger Band Standard Devaition Up", minval=1, maxval=5)
lb = input(50, title="Look Back Period Percentile High")
ph = input(.85, title="Highest Percentile - 0.90=90%, 0.95=95%, 0.99=99%")
// Use Original Criteria
sbc = input(false, title="Show Signal if WVF WAS True and IS Now False")
sbcc = input(false, title="Show Signal if WVF IS True")
// Use FILTERED Criteria
sbcFilt = input(true, title="Show Signal For Filtered Entry")
sbcAggr = input(true, title="Show Signal For AGGRESSIVE Filtered Entry")
ltLB = input(40, minval=25, maxval=99, title="Long-Term Look Back Current Bar Has To Close Below This Value OR Medium Term--Default=40")
mtLB = input(14, minval=10, maxval=20, title="Medium-Term Look Back Current Bar Has To Close Below This Value OR Long Term--Default=14")
str = input(3, minval=1, maxval=9, title="Entry Price Action Strength--Close > X Bars Back---Default=3")
// Williams Vix Fix Formula
wvf = ((highest(close, pd)-low)/(highest(close, pd)))*100
sDev = mult * stdev(wvf, length)
midLine = sma(wvf, length)
lowerBand = midLine - sDev
upperBand = midLine + sDev
rangeHigh = (highest(wvf, lb)) * ph
// Filtered Criteria
upRange = low > low[1] and close > high[1]
upRange_Aggr = close > close[1] and close > open[1]
// Filtered Criteria
filtered = ((wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and (wvf < upperBand and wvf < rangeHigh))
filtered_Aggr = (wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and not (wvf < upperBand and wvf < rangeHigh)
// Alerts Criteria
alert1 = wvf >= upperBand or wvf >= rangeHigh ? 1 : 0
alert2 = (wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and (wvf < upperBand and wvf < rangeHigh) ? 1 : 0
alert3 = upRange and close > close[str] and (close < close[ltLB] or close < close[mtLB]) and filtered ? 1 : 0
alert4 = upRange_Aggr and close > close[str] and (close < close[ltLB] or close < close[mtLB]) and filtered_Aggr ? 1 : 0
plotshape(show_VF and sbcc and alert1 ? alert1 : na, title="WVF Is True", color=color.new(#80FF00, 20), style=shape.triangledown, location=location.bottom, transp=0)
plotshape(show_VF and sbc and alert2 ? alert2 : na, title="WVF Was True - Now False", color=color.teal, style=shape.triangledown, location=location.bottom, transp=0)
plotshape(show_VF and sbcAggr and alert4 ? alert4 : na, title="Aggressive Entry", color=color.new(#80FF00, 60), style=shape.triangleup, location=location.bottom, size=size.tiny, text='AE')
plotshape(show_VF and sbcFilt and alert3 ? alert3 : na, title="Filtered Entry", color=color.new(#80FF00, 20), style=shape.triangleup, location=location.bottom, size=size.tiny, text='FE')