本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=4
study(shorttitle="TTM Squeeze Scanner", title="TTM Squeeze Scanner", overlay=false)
src = input(close, title="Source")
timeframe = input('240', type=input.resolution)
// ######################################################################################
// This script scans for TTM Squeezes for the crypto symbols below. The timeframe for
// the squeeze scan is controled within the input not the chart.
// This script is a merge of @Nico.Muselle's TTM Squeeze script and @QuantNomad's custom
// screener script. Thanks to both of them!
// ######################################################################################
//strict = input(true, title="Enabled (original) or Disabled (strict)")
length = input(20, minval=1, title="BB Length")
/// ### ORIGINAL TTM ### ///
bband(length, mult) =>
sma(close, length) + mult * stdev(close, length)
keltner(length, mult) =>
ema(close, length) + mult * ema(tr, length)
diff = bband(length, 2) - keltner(length, 1)
/// ### BOLLINGER BANDS ### ///
mult = input(2.0, minval=0.001, maxval=50, title="StDev")
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
/// ### KELTNER CHANNELS ### ///
useTrueRange = input(true)
klength = input(20, minval=1, title="Keltner Length")
kmult = input(1.0, title="Multiplier")
ksrc = input(close, title="Keltner Source")
ma = ema(src, klength)
range = useTrueRange ? tr : high - low
rangema = ema(range, klength)
kupper = ma + rangema * kmult
klower = ma - rangema * kmult
c = color.blue
/// ### CALCULATIONS ### ///
e1 = (highest(high, length) + lowest(low, length)) / 2 + sma(close, length)
osc = linreg(close - e1 / 2, length, 0)
color_1 = color.new(#00ffff, 70)
color_2 = color.new(#cc00cc, 70)
color_3 = color.new(#009b9b, 70)
color_4 = color.new(#ff9bff, 70)
osc_color = osc[1] < osc[0] ? osc[0] >= 0 ? color_1 : color_2 :
osc[0] >= 0 ? color_3 : color_4
//osc_color = osc[1] < osc[0] ? osc[0] >= 0 ? color(#00ffff, 40) : #cc00cc : osc[0] >= 0 ? #009b9b : #ff9bff
alert = true and diff < 0 ? true :
not true and kupper > upper and klower < lower ? true : false
alert2 = false and diff < 0 ? true :
not false and kupper > upper and klower < lower ? true : false
color_5 = color.new(color.orange, 1)
mid_color = alert ? color_5 : na
color_6 = color.new(color.lime, 1)
mid_color2 = alert2 ? color_6 : na
/// ### PLOTS ### ///
plot(osc, color=osc_color, style=plot.style_columns, linewidth=2, title="Hist. TTM")
plot(0, color=mid_color, style=plot.style_circles, linewidth=3, title="Loose TTM Fire")
plot(0, color=mid_color2, style=plot.style_circles, linewidth=3, title="Strict TTM Fire")
/// ### ALERT ### ///
alertcondition(alert, title="CTTV Loose Squeeze", message="Loose Squeeze alert")
alertcondition(alert2, title="CTTV Strict Squeeze", message="Strict Squeeze alert")
customFunc() => alert or alert2
s1 = security('BTCUSD', timeframe, customFunc())
s2 = security('ETHUSD', timeframe, customFunc())
s3 = security('XRPUSD', timeframe, customFunc())
s4 = security('LTCUSD', timeframe, customFunc())
s5 = security('USDTUSD', timeframe, customFunc())
s6 = security('EOSUSD', timeframe, customFunc())
s7 = security('BNBUSD', timeframe, customFunc())
s8 = security('BSVUSD', timeframe, customFunc())
s9 = security('XMRUSD', timeframe, customFunc())
s10 = security('ADAUSD', timeframe, customFunc())
s11 = security('XLMUSD', timeframe, customFunc())
s12 = security('LEOUSD', timeframe, customFunc())
s13 = security('TRXUSD', timeframe, customFunc())
s14 = security('DASHUSD', timeframe, customFunc())
s15 = security('ETCUSD', timeframe, customFunc())
s16 = security('XTZUSD', timeframe, customFunc())
s17 = security('IOTAUSD', timeframe, customFunc())
s18 = security('LINKUSD', timeframe, customFunc())
s19 = security('NEOUSD', timeframe, customFunc())
scr_label = 'Screener: \n##########\n'
scr_label := s1 ? scr_label + 'BTCUSD\n' : scr_label
scr_label := s2 ? scr_label + 'ETHUSD\n' : scr_label
scr_label := s3 ? scr_label + 'XRPUSD\n' : scr_label
scr_label := s4 ? scr_label + 'LTCUSD\n' : scr_label
scr_label := s5 ? scr_label + 'USDTUSD\n' : scr_label
scr_label := s6 ? scr_label + 'EOSUSD\n' : scr_label
scr_label := s7 ? scr_label + 'BNBUSD\n' : scr_label
scr_label := s8 ? scr_label + 'BSVUSD\n' : scr_label
scr_label := s9 ? scr_label + 'XMRUSD\n' : scr_label
scr_label := s10 ? scr_label + 'ADAUSD\n' : scr_label
scr_label := s11 ? scr_label + 'XLMUSD\n' : scr_label
scr_label := s12 ? scr_label + 'LEOUSD\n' : scr_label
scr_label := s13 ? scr_label + 'TRXUSD\n' : scr_label
scr_label := s14 ? scr_label + 'DASHUSD\n' : scr_label
scr_label := s15 ? scr_label + 'ETCUSD\n' : scr_label
scr_label := s16 ? scr_label + 'XTZUSD\n' : scr_label
scr_label := s17 ? scr_label + 'IOTAUSD\n' : scr_label
scr_label := s18 ? scr_label + 'LINKUSD\n' : scr_label
scr_label := s19 ? scr_label + 'NEOUSD\n' : scr_label
lab_l = label.new(
bar_index, 0, scr_label,
color=color.gray,
textcolor=color.black,
style = label.style_labeldown,
yloc = yloc.price)
label.delete(lab_l[1])
//plot(0, transp = 100)