本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © orbitonetv
//@version=6
indicator("Squeeze Radar [OrbitOne]", "Squeeze Radar [OrbitOne]", overlay = false, max_labels_count = 500, max_boxes_count = 200)
// ════════ LANGUAGE ════════
lang = input.string("English", "Chart language", options = ["English", "Türkçe", "Español", "Português", "Deutsch", "Français", "Русский", "中文"], tooltip = "Language of the labels, dashboard and alert() messages on the chart.")
// ════════ SQUEEZE ════════
gQ = "Squeeze"
len = input.int(20, "Length", minval = 5, group = gQ, tooltip = "Length of the Bollinger Bands, Keltner Channels and momentum.")
bbMult = input.float(2.0, "Bollinger Bands multiplier", minval = 0.5, step = 0.1, group = gQ)
sens = input.string("Medium (classic)", "Squeeze counts from", options = ["Loose", "Medium (classic)", "Tight"], group = gQ, tooltip = "Keltner multipliers: Loose = 2.0, Medium = 1.5 (classic), Tight = 1.0. The dots always show all three levels; this setting decides which level counts as a squeeze for signals, the dashboard and alerts.")
minSq = input.int(3, "Min squeeze length (bars)", minval = 1, group = gQ, tooltip = "A release only counts as a fire signal if the squeeze lasted at least this many bars.")
confirm = input.bool(true, "Wait for bar close", group = gQ, tooltip = "Fire signals appear only on closed bars and never repaint.")
// ════════ DISPLAY ════════
gV = "Display"
bullCol = input.color(#089981, "Bullish", inline = "c", group = gV)
bearCol = input.color(#F23645, "Bearish", inline = "c", group = gV)
onPrice = input.bool(true, "Show fire signals on price chart", group = gV)
showBox = input.bool(false, "Draw squeeze zones on price chart", group = gV, tooltip = "A box over the price bars that were inside the squeeze. The edges of the box are the range price broke out of.")
maxBox = input.int(20, "Squeeze zones kept", minval = 1, maxval = 200, group = gV)
// ════════ DASHBOARD ════════
gD = "Dashboard"
showDb = input.bool(true, "Show dashboard", group = gD)
tf1 = input.timeframe("60", "Timeframe 1", group = gD)
tf2 = input.timeframe("240", "Timeframe 2", group = gD)
tf3 = input.timeframe("D", "Timeframe 3", group = gD)
dbPos = input.string("Top right", "Position", options = ["Top right", "Bottom right", "Top left", "Bottom left"], group = gD)
dbSize = input.string("Tiny", "Size", options = ["Tiny", "Small", "Normal"], group = gD)
// ════════ TRANSLATIONS ════════
t(string en, string tr, string es, string pt, string de, string fr, string ru, string zh) =>
switch lang
"Türkçe" => tr
"Español" => es
"Português" => pt
"Deutsch" => de
"Français" => fr
"Русский" => ru
"中文" => zh
=> en
txtFireUp = t("FIRE ▲", "KIRILIM ▲", "DISPARO ▲", "DISPARO ▲", "AUSBRUCH ▲", "CASSURE ▲", "ПРОБОЙ ▲", "突破 ▲")
txtFireDn = t("FIRE ▼", "KIRILIM ▼", "DISPARO ▼", "DISPARO ▼", "AUSBRUCH ▼", "CASSURE ▼", "ПРОБОЙ ▼", "突破 ▼")
txtStatus = t("Status", "Durum", "Estado", "Estado", "Status", "Statut", "Статус", "状态")
txtOn = t("● Squeeze ON", "● Sıkışma VAR", "● Compresión", "● Compressão", "● Squeeze AKTIV", "● Compression", "● Сжатие", "● 挤压中")
txtOff = t("○ No squeeze", "○ Sıkışma yok", "○ Sin compresión", "○ Sem compressão", "○ Kein Squeeze", "○ Pas de compression", "○ Нет сжатия", "○ 无挤压")
txtLevel = t("Compression", "Sıkışma derecesi", "Nivel", "Nível", "Stufe", "Niveau", "Уровень", "级别")
txtTight = t("Tight", "Sıkı", "Fuerte", "Forte", "Stark", "Forte", "Сильное", "强")
txtMed = t("Medium", "Orta", "Media", "Média", "Mittel", "Moyenne", "Среднее", "中")
txtLoose = t("Loose", "Gevşek", "Débil", "Fraca", "Schwach", "Faible", "Слабое", "弱")
txtBars = t("Bars in squeeze", "Sıkışma süresi (mum)", "Velas en compresión", "Velas em compressão", "Kerzen im Squeeze", "Bougies en compression", "Свечей в сжатии", "挤压K线数")
txtMom = t("Momentum", "Momentum", "Impulso", "Momento", "Momentum", "Momentum", "Импульс", "动量")
txtRise = t("▲ Rising", "▲ Artıyor", "▲ Subiendo", "▲ Subindo", "▲ Steigend", "▲ Hausse", "▲ Растёт", "▲ 上升")
txtFall = t("▼ Falling", "▼ Azalıyor", "▼ Bajando", "▼ Caindo", "▼ Fallend", "▼ Baisse", "▼ Падает", "▼ 下降")
txtLast = t("Last fire", "Son kırılım", "Último disparo", "Último disparo", "Letzter Ausbruch", "Dernière cassure", "Последний пробой", "最近突破")
txtAgo = t("Bars ago", "Kaç mum önce", "Velas atrás", "Velas atrás", "Kerzen her", "Bougies depuis", "Свечей назад", "K线前")
txtRank = t("Volatility rank", "Oynaklık sırası", "Rango de volatilidad", "Ranking de volatilidade", "Volatilitätsrang", "Rang de volatilité", "Ранг волатильности", "波动率排名")
// ════════ CALCULATION ════════
// returns compression level: 3 = tight (KC 1.0), 2 = medium (KC 1.5), 1 = loose (KC 2.0), 0 = none
f_level() =>
float basis = ta.sma(close, len)
float dev = bbMult * ta.stdev(close, len)
float rng = ta.sma(ta.tr(true), len)
float bbU = basis + dev
float bbL = basis - dev
bbU < basis + rng * 1.0 and bbL > basis - rng * 1.0 ? 3 : bbU < basis + rng * 1.5 and bbL > basis - rng * 1.5 ? 2 : bbU < basis + rng * 2.0 and bbL > basis - rng * 2.0 ? 1 : 0
minLvl = sens == "Tight" ? 3 : sens == "Loose" ? 1 : 2
f_htf() =>
int l = f_level()
l[1]
lvl = f_level()
inSq = lvl >= minLvl
mom = ta.linreg(close - math.avg(math.avg(ta.highest(high, len), ta.lowest(low, len)), ta.sma(close, len)), len, 0)
bbW = 2 * bbMult * ta.stdev(close, len) / ta.sma(close, len)
rankV = ta.percentrank(bbW, 120)
h1 = request.security(syminfo.tickerid, tf1, f_htf(), lookahead = barmerge.lookahead_on)
h2 = request.security(syminfo.tickerid, tf2, f_htf(), lookahead = barmerge.lookahead_on)
h3 = request.security(syminfo.tickerid, tf3, f_htf(), lookahead = barmerge.lookahead_on)
// squeeze duration
var int sqBars = 0
sqBars := inSq ? sqBars + 1 : 0
prevLen = sqBars[1]
okBar = not confirm or barstate.isconfirmed
released = inSq[1] and not inSq and prevLen >= minSq
fireUp = released and mom > 0 and okBar
fireDn = released and mom <= 0 and okBar
sqStart = inSq and not inSq[1]
var int lastDir = 0
var int lastBar = na
if fireUp or fireDn
lastDir := fireUp ? 1 : -1
lastBar := bar_index
// ════════ PLOTS ════════
momCol = mom >= 0 ? (mom >= nz(mom[1]) ? bullCol : color.new(bullCol, 55)) : (mom <= nz(mom[1]) ? bearCol : color.new(bearCol, 55))
plot(mom, "Momentum", color = momCol, style = plot.style_columns)
dotCol = lvl == 3 ? #FF9800 : lvl == 2 ? #F23645 : lvl == 1 ? #434651 : #4CAF50
plot(0, "Squeeze dots", color = dotCol, style = plot.style_circles, linewidth = 3, display = display.all - display.status_line)
plotshape(fireUp, "Fire up (pane)", shape.triangleup, location.bottom, bullCol, size = size.tiny, display = display.all - display.status_line)
plotshape(fireDn, "Fire down (pane)", shape.triangledown, location.top, bearCol, size = size.tiny, display = display.all - display.status_line)
if onPrice and fireUp
label.new(bar_index, low, txtFireUp, yloc = yloc.belowbar, style = label.style_label_up, color = bullCol, textcolor = color.white, size = size.small, force_overlay = true)
if onPrice and fireDn
label.new(bar_index, high, txtFireDn, yloc = yloc.abovebar, style = label.style_label_down, color = bearCol, textcolor = color.white, size = size.small, force_overlay = true)
// squeeze zones on price
var array<box> zones = array.new<box>()
var box zb = na
var float zH = na
var float zL = na
if showBox
if sqStart
zH := high
zL := low
zb := box.new(bar_index, high, bar_index, low, border_color = color.new(#FF9800, 30), bgcolor = color.new(#FF9800, 88), border_style = line.style_dashed, force_overlay = true)
zones.push(zb)
while zones.size() > maxBox
box.delete(zones.shift())
else if inSq and not na(zb)
zH := math.max(zH, high)
zL := math.min(zL, low)
box.set_top(zb, zH)
box.set_bottom(zb, zL)
box.set_right(zb, bar_index)
else if not inSq
zb := na
// ════════ DASHBOARD ════════
var table db = table.new(dbPos == "Top right" ? position.top_right : dbPos == "Bottom right" ? position.bottom_right : dbPos == "Top left" ? position.top_left : position.bottom_left, 2, 10, border_width = 1, force_overlay = true)
tSize = dbSize == "Tiny" ? size.tiny : dbSize == "Normal" ? size.normal : size.small
f_tf(string tf) =>
tf == "D" or tf == "1D" ? "1D" : tf == "W" or tf == "1W" ? "1W" : tf == "M" or tf == "1M" ? "1M" : str.endswith(tf, "S") ? tf : timeframe.in_seconds(tf) >= 3600 ? str.tostring(timeframe.in_seconds(tf) / 3600) + "H" : tf + "m"
f_row(int r, string k, string v, color c) =>
table.cell(db, 0, r, k, bgcolor = color.new(color.gray, 35), text_color = color.white, text_size = tSize)
table.cell(db, 1, r, v, bgcolor = c, text_color = color.white, text_size = tSize)
lvlTxt(int l) =>
l == 3 ? txtTight : l == 2 ? txtMed : l == 1 ? txtLoose : "—"
lvlCol(int l) =>
l == 3 ? color.new(#FF9800, 10) : l == 2 ? color.new(#F23645, 20) : l == 1 ? color.new(#434651, 10) : color.new(#4CAF50, 20)
sqTxt(int l) =>
l >= minLvl ? txtOn + " · " + lvlTxt(l) : txtOff
if showDb and barstate.isfirst
table.merge_cells(db, 0, 0, 1, 0)
if showDb and barstate.islast
color nc = color.new(color.gray, 20)
table.cell(db, 0, 0, "Squeeze Radar · " + str.tostring(len) + " · OrbitOne", bgcolor = color.new(color.black, 30), text_color = color.white, text_size = tSize)
f_row(1, txtStatus, inSq ? txtOn : txtOff, inSq ? lvlCol(lvl) : lvlCol(0))
f_row(2, txtLevel, lvlTxt(lvl), lvlCol(lvl))
f_row(3, txtBars, inSq ? str.tostring(sqBars) : "—", nc)
f_row(4, txtMom, mom >= nz(mom[1]) ? txtRise : txtFall, mom >= 0 ? color.new(bullCol, 20) : color.new(bearCol, 20))
f_row(5, txtLast, lastDir == 1 ? txtFireUp : lastDir == -1 ? txtFireDn : "—", lastDir == 1 ? bullCol : lastDir == -1 ? bearCol : color.gray)
f_row(6, txtAgo, na(lastBar) ? "—" : str.tostring(bar_index - lastBar), nc)
f_row(7, f_tf(tf1), sqTxt(h1), lvlCol(h1 >= minLvl ? h1 : 0))
f_row(8, f_tf(tf2), sqTxt(h2), lvlCol(h2 >= minLvl ? h2 : 0))
f_row(9, f_tf(tf3), sqTxt(h3), lvlCol(h3 >= minLvl ? h3 : 0))
// ════════ ALERTS ════════
alertcondition(sqStart and okBar, "Squeeze started", "Squeeze started | {{ticker}} | {{interval}} | {{close}}")
alertcondition(fireUp, "Fire up", "Squeeze fired UP | {{ticker}} | {{interval}} | {{close}}")
alertcondition(fireDn, "Fire down", "Squeeze fired DOWN | {{ticker}} | {{interval}} | {{close}}")
alertcondition(fireUp or fireDn, "Any fire", "Squeeze fired | {{ticker}} | {{interval}} | {{close}}")
// alert() messages follow the chart language. Create the alert with "Any alert() function call".
freq = confirm ? alert.freq_once_per_bar_close : alert.freq_once_per_bar
if fireUp
alert("Squeeze Radar " + txtFireUp + " | " + syminfo.ticker + " | " + timeframe.period + " | " + str.tostring(close, format.mintick), freq)
if fireDn
alert("Squeeze Radar " + txtFireDn + " | " + syminfo.ticker + " | " + timeframe.period + " | " + str.tostring(close, format.mintick), freq)