本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// © Trader_Yunis | Y.Algo
//@version=6
indicator(title="Ribbon Trend | 絲帶趨勢 [Y.Algo]", shorttitle="Ribbon Trend [Y.Algo]", overlay=true, max_labels_count=50)
// ══════════════════════════════════════════════════════════════════════════════
// ██ INPUT GROUPS ██
// ══════════════════════════════════════════════════════════════════════════════
group_theme = "顏色主題設定 | Color Theme Settings"
group_ma = "均線設定 | Moving Averages"
group_ribbon = "均線絲帶 | MA Ribbon"
group_vegas = "維加斯通道 | Vegas Channel"
group_lbl = "標籤 | Labels"
group_alerts = "快訊設置 | Alerts"
// ─── 顏色主題 | Color Theme ──────────────────────────────────────────────────
color_theme = input.string("經典暖色 | Classic Warm", "顏色主題 | Color Theme", options=["經典暖色 | Classic Warm", "霓虹冷色 | Neon Cool", "自訂 | Custom"], group=group_theme, tooltip="主題決定均線、絲帶與通道的顏色;自訂才採用各項顏色設定。\nTheme sets MA, ribbon and channel colors; color inputs apply only under Custom.")
// ─── 均線設定 | Moving Averages ──────────────────────────────────────────────
show_all_ma = input.bool(true, "顯示全部均線 | Show All MAs", group=group_ma, tooltip="一鍵開關四條均線,個別勾選會保留。\nTurns all four MAs on or off; individual ticks are kept.")
ma_type = input.string("EMA", "均線類型 | MA Type", options=["SMA", "EMA"], group=group_ma, tooltip="四條均線共用的計算方法。\nMA calculation method shared by all four lines.")
in_show_ma1 = input.bool(true, "顯示均線 1 | Show MA 1", inline="m1", group=group_ma, tooltip="勾選、週期、顏色(顏色僅自訂主題採用)。\nToggle, period, color (color applies under Custom).")
ma_len_1 = input.int(21, "", minval=1, inline="m1", group=group_ma)
ma_col_1_in = input.color(#FFD54F, "", inline="m1", group=group_ma)
in_show_ma2 = input.bool(true, "顯示均線 2 | Show MA 2", inline="m2", group=group_ma)
ma_len_2 = input.int(55, "", minval=1, inline="m2", group=group_ma)
ma_col_2_in = input.color(#FFA726, "", inline="m2", group=group_ma)
in_show_ma3 = input.bool(true, "顯示均線 3 | Show MA 3", inline="m3", group=group_ma)
ma_len_3 = input.int(100, "", minval=1, inline="m3", group=group_ma)
ma_col_3_in = input.color(#9E9E9E, "", inline="m3", group=group_ma)
in_show_ma4 = input.bool(true, "顯示均線 4 | Show MA 4", inline="m4", group=group_ma)
ma_len_4 = input.int(200, "", minval=1, inline="m4", group=group_ma)
ma_col_4_in = input.color(#9E9E9E, "", inline="m4", group=group_ma)
// ─── 均線絲帶 | MA Ribbon ────────────────────────────────────────────────────
show_ribbon = input.bool(true, "顯示絲帶 | Show Ribbon", group=group_ribbon, tooltip="絲帶邊界對齊四條均線;各層看短線是否在長線上方決定多空色。\nRibbon edges follow the four MAs; each layer is bull or bear by its shorter line vs. longer line.")
show_candles = input.bool(true, "漸層 K 棒 | Gradient Candles", group=group_ribbon, tooltip="依絲帶多空狀態著色,短期趨勢越明確越亮;請隱藏原本的 K 棒。\nColored by ribbon state, brighter when the short-term trend is clear; hide the chart's own candles.")
rb_transp = input.int(50, "絲帶透明度 | Ribbon Transparency", minval=0, maxval=100, group=group_ribbon, tooltip="最內層透明度,往外自動變淡。\nInnermost layer transparency; outer layers fade automatically.")
rb_bull_1_in = input.color(#557571, "多頭顏色層 1 | Bull Layer 1", group=group_ribbon, tooltip="僅自訂主題採用。\nApplies only under Custom.")
rb_bull_2_in = input.color(#4D6A66, "多頭顏色層 2 | Bull Layer 2", group=group_ribbon)
rb_bull_3_in = input.color(#445E5B, "多頭顏色層 3 | Bull Layer 3", group=group_ribbon)
rb_bull_4_in = input.color(#3C5350, "多頭顏色層 4 | Bull Layer 4", group=group_ribbon)
rb_bull_5_in = input.color(#344846, "多頭顏色層 5 | Bull Layer 5", group=group_ribbon)
rb_bull_6_in = input.color(#2B3C3B, "多頭顏色層 6 | Bull Layer 6", group=group_ribbon)
rb_bull_7_in = input.color(#233130, "多頭顏色層 7 | Bull Layer 7", group=group_ribbon)
rb_bear_1_in = input.color(#D49A89, "空頭顏色層 1 | Bear Layer 1", group=group_ribbon)
rb_bear_2_in = input.color(#BE8A7B, "空頭顏色層 2 | Bear Layer 2", group=group_ribbon)
rb_bear_3_in = input.color(#A97A6C, "空頭顏色層 3 | Bear Layer 3", group=group_ribbon)
rb_bear_4_in = input.color(#946A5E, "空頭顏色層 4 | Bear Layer 4", group=group_ribbon)
rb_bear_5_in = input.color(#7E5A50, "空頭顏色層 5 | Bear Layer 5", group=group_ribbon)
rb_bear_6_in = input.color(#684A41, "空頭顏色層 6 | Bear Layer 6", group=group_ribbon)
rb_bear_7_in = input.color(#533A33, "空頭顏色層 7 | Bear Layer 7", group=group_ribbon)
// ─── 維加斯通道 | Vegas Channel ───────────────────────────────────────────────
vegas_mode = input.string("關閉 | Off", "維加斯通道 | Vegas Channel", options=["關閉 | Off", "144 / 169", "576 / 676", "兩組 | Both"], group=group_vegas, tooltip="顯示短通道、長通道、兩組或關閉。\nShow the short channel, long channel, both, or none.")
vg_bull_col = input.color(#557571, "上升色 | Bull Color", group=group_vegas, tooltip="快線在慢線上方時的通道色。\nChannel color when fast EMA is above slow EMA.")
vg_bear_col = input.color(#D49A89, "下降色 | Bear Color", group=group_vegas, tooltip="快線在慢線下方時的通道色。\nChannel color when fast EMA is below slow EMA.")
vg_fill_transp = input.int(80, "填色透明度 | Fill Transparency", minval=0, maxval=100, group=group_vegas, tooltip="數值越大越透明。\nHigher = more transparent.")
// ─── 標籤 | Labels ────────────────────────────────────────────────────────────
show_lbl = input.bool(true, "顯示價格標籤 | Show Value Labels", group=group_lbl, tooltip="在最新 K 棒右側顯示均線與通道數值,文字顏色同線色。\nValue labels at the right of the latest bar, text colored like the line.")
lbl_offset = input.int(2, "標籤右移 | Label Offset", minval=0, maxval=30, group=group_lbl, tooltip="標籤離最新 K 棒的根數;被遮住就調大。\nBars between the latest candle and the labels; raise it if labels get covered.")
// ─── 快訊設置 | Alerts ─────────────────────────────────────────────────────────
al_ma1 = input.bool(true, "觸碰均線 1 | Touch MA 1", group=group_alerts, tooltip="K 棒碰到均線的第一根觸發;需顯示該均線。\nFires on the first bar touching the MA; the MA must be shown.")
al_ma2 = input.bool(true, "觸碰均線 2 | Touch MA 2", group=group_alerts)
al_ma3 = input.bool(true, "觸碰均線 3 | Touch MA 3", group=group_alerts)
al_ma4 = input.bool(true, "觸碰均線 4 | Touch MA 4", group=group_alerts)
al_vg_s = input.bool(true, "觸碰維加斯 144/169 | Touch Vegas 144/169", group=group_alerts, tooltip="K 棒進入通道的第一根觸發;需顯示該通道。\nFires on the first bar entering the channel; the channel must be shown.")
al_vg_l = input.bool(true, "觸碰維加斯 576/676 | Touch Vegas 576/676", group=group_alerts)
// ══════════════════════════════════════════════════════════════════════════════
// ██ THEME COLOR DERIVATIONS ██
// ══════════════════════════════════════════════════════════════════════════════
_isCool = color_theme == "霓虹冷色 | Neon Cool"
_isCustom = color_theme == "自訂 | Custom"
theme_bull = _isCool ? #00bcd4 : #557571
theme_bear = _isCool ? #e91e63 : #D49A89
vg_bull = _isCustom ? vg_bull_col : theme_bull
vg_bear = _isCustom ? vg_bear_col : theme_bear
rb_bull_1 = _isCustom ? rb_bull_1_in : _isCool ? #00BCD4 : #557571
rb_bull_2 = _isCustom ? rb_bull_2_in : _isCool ? #00ADC3 : #4D6A66
rb_bull_3 = _isCustom ? rb_bull_3_in : _isCool ? #009DB2 : #445E5B
rb_bull_4 = _isCustom ? rb_bull_4_in : _isCool ? #008EA0 : #3C5350
rb_bull_5 = _isCustom ? rb_bull_5_in : _isCool ? #007F8F : #344846
rb_bull_6 = _isCustom ? rb_bull_6_in : _isCool ? #006F7E : #2B3C3B
rb_bull_7 = _isCustom ? rb_bull_7_in : _isCool ? #00606D : #233130
rb_bear_1 = _isCustom ? rb_bear_1_in : _isCool ? #E91E63 : #D49A89
rb_bear_2 = _isCustom ? rb_bear_2_in : _isCool ? #D61C5B : #BE8A7B
rb_bear_3 = _isCustom ? rb_bear_3_in : _isCool ? #C31A53 : #A97A6C
rb_bear_4 = _isCustom ? rb_bear_4_in : _isCool ? #B0184B : #946A5E
rb_bear_5 = _isCustom ? rb_bear_5_in : _isCool ? #9D1643 : #7E5A50
rb_bear_6 = _isCustom ? rb_bear_6_in : _isCool ? #8A143B : #684A41
rb_bear_7 = _isCustom ? rb_bear_7_in : _isCool ? #771233 : #533A33
show_ma1 = show_all_ma and in_show_ma1
show_ma2 = show_all_ma and in_show_ma2
show_ma3 = show_all_ma and in_show_ma3
show_ma4 = show_all_ma and in_show_ma4
// ══════════════════════════════════════════════════════════════════════════════
// ██ CALCULATIONS ██
// ══════════════════════════════════════════════════════════════════════════════
f_ma(int len) =>
_s = ta.sma(close, len)
_e = ta.ema(close, len)
ma_type == "SMA" ? _s : _e
ma1 = f_ma(ma_len_1)
ma2 = f_ma(ma_len_2)
ma3 = f_ma(ma_len_3)
ma4 = f_ma(ma_len_4)
// 均線主題色:高於下一條較長均線取多頭色,最長一條看自身斜率 | Theme MA color: bull when above the next longer MA; the longest uses its own slope
ma_theme_col_1 = ma1 >= ma2 ? rb_bull_1 : rb_bear_1
ma_theme_col_2 = ma2 >= ma3 ? rb_bull_2 : rb_bear_2
ma_theme_col_3 = ma3 >= ma4 ? rb_bull_3 : rb_bear_3
ma_theme_col_4 = ma4 >= nz(ma4[1], ma4) ? rb_bull_3 : rb_bear_3
ma_col_1 = _isCustom ? ma_col_1_in : ma_theme_col_1
ma_col_2 = _isCustom ? ma_col_2_in : ma_theme_col_2
ma_col_3 = _isCustom ? ma_col_3_in : ma_theme_col_3
ma_col_4 = _isCustom ? ma_col_4_in : ma_theme_col_4
// 絲帶節點:邊界對齊四條均線週期,每段再插兩條 | Ribbon nodes: edges follow the four MA periods, two extra nodes per segment
rb_e0 = ta.ema(close, ma_len_1)
rb_e1 = ta.ema(close, math.max(1, int(math.round(ma_len_1 + (ma_len_2 - ma_len_1) / 3.0))))
rb_e2 = ta.ema(close, math.max(1, int(math.round(ma_len_1 + (ma_len_2 - ma_len_1) * 2.0 / 3.0))))
rb_e3 = ta.ema(close, ma_len_2)
rb_e4 = ta.ema(close, math.max(1, int(math.round(ma_len_2 + (ma_len_3 - ma_len_2) / 3.0))))
rb_e5 = ta.ema(close, math.max(1, int(math.round(ma_len_2 + (ma_len_3 - ma_len_2) * 2.0 / 3.0))))
rb_e6 = ta.ema(close, ma_len_3)
rb_e7 = ta.ema(close, math.max(1, int(math.round(ma_len_3 + (ma_len_4 - ma_len_3) / 3.0))))
rb_e8 = ta.ema(close, math.max(1, int(math.round(ma_len_3 + (ma_len_4 - ma_len_3) * 2.0 / 3.0))))
rb_e9 = ta.ema(close, ma_len_4)
f_pick(int lvl, color c1, color c2, color c3, color c4, color c5, color c6, color c7) =>
switch lvl
1 => c1
2 => c2
3 => c3
4 => c4
5 => c5
6 => c6
=> c7
// 七色連續漸層,pos 範圍 0–6 | Seven-color gradient, pos in 0–6
f_grad7(float pos, color c1, color c2, color c3, color c4, color c5, color c6, color c7) =>
_lo = math.min(int(math.floor(pos)), 5)
color.from_gradient(pos - _lo, 0.0, 1.0, f_pick(_lo + 1, c1, c2, c3, c4, c5, c6, c7), f_pick(_lo + 2, c1, c2, c3, c4, c5, c6, c7))
rb_bd0 = rb_e0 >= rb_e1
rb_bd1 = rb_e1 >= rb_e2
rb_bd2 = rb_e2 >= rb_e3
rb_bd3 = rb_e3 >= rb_e4
rb_bd4 = rb_e4 >= rb_e5
rb_bd5 = rb_e5 >= rb_e6
rb_bd6 = rb_e6 >= rb_e7
rb_bd7 = rb_e7 >= rb_e8
rb_bd8 = rb_e8 >= rb_e9
// K 棒強度:短段權重最高,主導方權重越高顏色越亮 | Candle strength: shorter segments weigh more, higher dominance = brighter
rb_bullW = (rb_bd0 ? 3 : 0) + (rb_bd1 ? 3 : 0) + (rb_bd2 ? 3 : 0) + (rb_bd3 ? 2 : 0) + (rb_bd4 ? 2 : 0) + (rb_bd5 ? 2 : 0) + (rb_bd6 ? 1 : 0) + (rb_bd7 ? 1 : 0) + (rb_bd8 ? 1 : 0)
rb_isBull = rb_bullW > 9 or (rb_bullW == 9 and rb_bd0)
rb_domW = rb_isBull ? rb_bullW : 18 - rb_bullW
rb_lvl = math.min(7, 1 + int((18 - rb_domW) * 7.0 / 10.0))
rb_candle_col = rb_isBull ? f_pick(rb_lvl, rb_bull_1, rb_bull_2, rb_bull_3, rb_bull_4, rb_bull_5, rb_bull_6, rb_bull_7) : f_pick(rb_lvl, rb_bear_1, rb_bear_2, rb_bear_3, rb_bear_4, rb_bear_5, rb_bear_6, rb_bear_7)
vg_s_f = ta.ema(close, 144)
vg_s_s = ta.ema(close, 169)
vg_l_f = ta.ema(close, 576)
vg_l_s = ta.ema(close, 676)
show_vg_s = vegas_mode == "144 / 169" or vegas_mode == "兩組 | Both"
show_vg_l = vegas_mode == "576 / 676" or vegas_mode == "兩組 | Both"
vg_s_top = math.max(vg_s_f, vg_s_s)
vg_s_bot = math.min(vg_s_f, vg_s_s)
vg_l_top = math.max(vg_l_f, vg_l_s)
vg_l_bot = math.min(vg_l_f, vg_l_s)
// ══════════════════════════════════════════════════════════════════════════════
// ██ VISUALS ██
// ══════════════════════════════════════════════════════════════════════════════
// 隱藏節點只作填色錨點 | Hidden nodes serve as fill anchors
rbT = rb_transp
p_qe0 = plot(show_ribbon ? rb_e0 : na, "絲帶節點 1 | Ribbon Node 1", display=display.none)
p_qe1 = plot(show_ribbon ? rb_e1 : na, "絲帶節點 2 | Ribbon Node 2", display=display.none)
p_qe2 = plot(show_ribbon ? rb_e2 : na, "絲帶節點 3 | Ribbon Node 3", display=display.none)
p_qe3 = plot(show_ribbon ? rb_e3 : na, "絲帶節點 4 | Ribbon Node 4", display=display.none)
p_qe4 = plot(show_ribbon ? rb_e4 : na, "絲帶節點 5 | Ribbon Node 5", display=display.none)
p_qe5 = plot(show_ribbon ? rb_e5 : na, "絲帶節點 6 | Ribbon Node 6", display=display.none)
p_qe6 = plot(show_ribbon ? rb_e6 : na, "絲帶節點 7 | Ribbon Node 7", display=display.none)
p_qe7 = plot(show_ribbon ? rb_e7 : na, "絲帶節點 8 | Ribbon Node 8", display=display.none)
p_qe8 = plot(show_ribbon ? rb_e8 : na, "絲帶節點 9 | Ribbon Node 9", display=display.none)
p_qe9 = plot(show_ribbon ? rb_e9 : na, "絲帶節點 10 | Ribbon Node 10", display=display.none)
fill(p_qe0, p_qe1, color.new(rb_bd0 ? f_grad7(0.3333, rb_bull_1, rb_bull_2, rb_bull_3, rb_bull_4, rb_bull_5, rb_bull_6, rb_bull_7) : f_grad7(0.3333, rb_bear_1, rb_bear_2, rb_bear_3, rb_bear_4, rb_bear_5, rb_bear_6, rb_bear_7), math.min(100, rbT + 1.11)), title="絲帶層 1 | Ribbon Band 1")
fill(p_qe1, p_qe2, color.new(rb_bd1 ? f_grad7(1.0, rb_bull_1, rb_bull_2, rb_bull_3, rb_bull_4, rb_bull_5, rb_bull_6, rb_bull_7) : f_grad7(1.0, rb_bear_1, rb_bear_2, rb_bear_3, rb_bear_4, rb_bear_5, rb_bear_6, rb_bear_7), math.min(100, rbT + 3.33)), title="絲帶層 2 | Ribbon Band 2")
fill(p_qe2, p_qe3, color.new(rb_bd2 ? f_grad7(1.6667, rb_bull_1, rb_bull_2, rb_bull_3, rb_bull_4, rb_bull_5, rb_bull_6, rb_bull_7) : f_grad7(1.6667, rb_bear_1, rb_bear_2, rb_bear_3, rb_bear_4, rb_bear_5, rb_bear_6, rb_bear_7), math.min(100, rbT + 5.56)), title="絲帶層 3 | Ribbon Band 3")
fill(p_qe3, p_qe4, color.new(rb_bd3 ? f_grad7(2.3333, rb_bull_1, rb_bull_2, rb_bull_3, rb_bull_4, rb_bull_5, rb_bull_6, rb_bull_7) : f_grad7(2.3333, rb_bear_1, rb_bear_2, rb_bear_3, rb_bear_4, rb_bear_5, rb_bear_6, rb_bear_7), math.min(100, rbT + 7.78)), title="絲帶層 4 | Ribbon Band 4")
fill(p_qe4, p_qe5, color.new(rb_bd4 ? f_grad7(3.0, rb_bull_1, rb_bull_2, rb_bull_3, rb_bull_4, rb_bull_5, rb_bull_6, rb_bull_7) : f_grad7(3.0, rb_bear_1, rb_bear_2, rb_bear_3, rb_bear_4, rb_bear_5, rb_bear_6, rb_bear_7), math.min(100, rbT + 10.0)), title="絲帶層 5 | Ribbon Band 5")
fill(p_qe5, p_qe6, color.new(rb_bd5 ? f_grad7(3.6667, rb_bull_1, rb_bull_2, rb_bull_3, rb_bull_4, rb_bull_5, rb_bull_6, rb_bull_7) : f_grad7(3.6667, rb_bear_1, rb_bear_2, rb_bear_3, rb_bear_4, rb_bear_5, rb_bear_6, rb_bear_7), math.min(100, rbT + 12.22)), title="絲帶層 6 | Ribbon Band 6")
fill(p_qe6, p_qe7, color.new(rb_bd6 ? f_grad7(4.3333, rb_bull_1, rb_bull_2, rb_bull_3, rb_bull_4, rb_bull_5, rb_bull_6, rb_bull_7) : f_grad7(4.3333, rb_bear_1, rb_bear_2, rb_bear_3, rb_bear_4, rb_bear_5, rb_bear_6, rb_bear_7), math.min(100, rbT + 14.44)), title="絲帶層 7 | Ribbon Band 7")
fill(p_qe7, p_qe8, color.new(rb_bd7 ? f_grad7(5.0, rb_bull_1, rb_bull_2, rb_bull_3, rb_bull_4, rb_bull_5, rb_bull_6, rb_bull_7) : f_grad7(5.0, rb_bear_1, rb_bear_2, rb_bear_3, rb_bear_4, rb_bear_5, rb_bear_6, rb_bear_7), math.min(100, rbT + 16.67)), title="絲帶層 8 | Ribbon Band 8")
fill(p_qe8, p_qe9, color.new(rb_bd8 ? f_grad7(5.6667, rb_bull_1, rb_bull_2, rb_bull_3, rb_bull_4, rb_bull_5, rb_bull_6, rb_bull_7) : f_grad7(5.6667, rb_bear_1, rb_bear_2, rb_bear_3, rb_bear_4, rb_bear_5, rb_bear_6, rb_bear_7), math.min(100, rbT + 18.89)), title="絲帶層 9 | Ribbon Band 9")
_cc = show_candles ? rb_candle_col : na
plotcandle(open, high, low, close, "漸層 K 棒 | Gradient Candles", color=_cc, wickcolor=_cc, bordercolor=_cc)
plot(show_ma1 ? ma1 : na, "均線 1 | MA 1", color=ma_col_1)
plot(show_ma2 ? ma2 : na, "均線 2 | MA 2", color=ma_col_2)
plot(show_ma3 ? ma3 : na, "均線 3 | MA 3", color=ma_col_3)
plot(show_ma4 ? ma4 : na, "均線 4 | MA 4", color=ma_col_4)
vg_s_col = vg_s_f >= vg_s_s ? vg_bull : vg_bear
vg_l_col = vg_l_f >= vg_l_s ? vg_bull : vg_bear
p_vsf = plot(show_vg_s ? vg_s_f : na, "維加斯 144 | Vegas 144", color=color.new(vg_s_col, 30), linewidth=1)
p_vss = plot(show_vg_s ? vg_s_s : na, "維加斯 169 | Vegas 169", color=color.new(vg_s_col, 30), linewidth=1)
p_vlf = plot(show_vg_l ? vg_l_f : na, "維加斯 576 | Vegas 576", color=color.new(vg_l_col, 30), linewidth=1)
p_vls = plot(show_vg_l ? vg_l_s : na, "維加斯 676 | Vegas 676", color=color.new(vg_l_col, 30), linewidth=1)
fill(p_vsf, p_vss, color.new(vg_s_col, vg_fill_transp), title="維加斯 144/169 填色 | Vegas 144/169 Fill")
fill(p_vlf, p_vls, color.new(vg_l_col, vg_fill_transp), title="維加斯 576/676 填色 | Vegas 576/676 Fill")
// 數值標籤:在最後一根 K 棒重畫 | Value labels, redrawn on the last bar
var label[] lbls = array.new_label(0)
f_addLbl(bool _on, float _y, string _txt, color _c) =>
if _on and not na(_y)
array.push(lbls, label.new(bar_index + lbl_offset, _y, _txt + " " + str.tostring(_y, format.mintick), color=color.new(color.black, 100), textcolor=_c, style=label.style_label_left, size=size.small))
if barstate.islast
if array.size(lbls) > 0
for i = 0 to array.size(lbls) - 1
label.delete(array.get(lbls, i))
array.clear(lbls)
if show_lbl
f_addLbl(show_ma1, ma1, ma_type + " " + str.tostring(ma_len_1), ma_col_1)
f_addLbl(show_ma2, ma2, ma_type + " " + str.tostring(ma_len_2), ma_col_2)
f_addLbl(show_ma3, ma3, ma_type + " " + str.tostring(ma_len_3), ma_col_3)
f_addLbl(show_ma4, ma4, ma_type + " " + str.tostring(ma_len_4), ma_col_4)
f_addLbl(show_vg_s, vg_s_top, "Vegas 144/169 ▲", vg_s_col)
f_addLbl(show_vg_s, vg_s_bot, "Vegas 144/169 ▼", vg_s_col)
f_addLbl(show_vg_l, vg_l_top, "Vegas 576/676 ▲", vg_l_col)
f_addLbl(show_vg_l, vg_l_bot, "Vegas 576/676 ▼", vg_l_col)
// ══════════════════════════════════════════════════════════════════════════════
// ██ ALERTS | 快訊 ██
// ══════════════════════════════════════════════════════════════════════════════
f_tfStr() =>
_s = timeframe.in_seconds(timeframe.period)
_out = str.tostring(_s) + "s"
if _s >= 86400
_out := str.tostring(_s / 86400.0, "#.##") + "D"
else if _s >= 3600
_out := str.tostring(_s / 3600.0, "#.##") + "H"
else if _s >= 60
_out := str.tostring(_s / 60.0, "#.##") + "m"
_out
f_alert(_fire, _zh, _en) =>
if _fire
alert(syminfo.ticker + " " + f_tfStr() + " " + str.tostring(close, format.mintick) + " — Ribbon: " + _zh + " | " + _en, alert.freq_once_per_bar_close)
// 觸碰:K 棒範圍碰到線或進入通道,只在第一根觸發 | Touch: bar range meets the line or channel, first bar only
t_ma1 = low <= ma1 and high >= ma1
t_ma2 = low <= ma2 and high >= ma2
t_ma3 = low <= ma3 and high >= ma3
t_ma4 = low <= ma4 and high >= ma4
t_vgs = low <= vg_s_top and high >= vg_s_bot
t_vgl = low <= vg_l_top and high >= vg_l_bot
_alM1 = al_ma1 and show_ma1 and t_ma1 and not t_ma1[1]
_alM2 = al_ma2 and show_ma2 and t_ma2 and not t_ma2[1]
_alM3 = al_ma3 and show_ma3 and t_ma3 and not t_ma3[1]
_alM4 = al_ma4 and show_ma4 and t_ma4 and not t_ma4[1]
_alVs = al_vg_s and show_vg_s and t_vgs and not t_vgs[1]
_alVl = al_vg_l and show_vg_l and t_vgl and not t_vgl[1]
alertcondition(_alM1, "◆ 觸碰均線 1 | Touch MA 1", "{{ticker}} {{interval}} {{close}} — Ribbon: 觸碰均線 1 | Price touched MA 1")
alertcondition(_alM2, "◆ 觸碰均線 2 | Touch MA 2", "{{ticker}} {{interval}} {{close}} — Ribbon: 觸碰均線 2 | Price touched MA 2")
alertcondition(_alM3, "◆ 觸碰均線 3 | Touch MA 3", "{{ticker}} {{interval}} {{close}} — Ribbon: 觸碰均線 3 | Price touched MA 3")
alertcondition(_alM4, "◆ 觸碰均線 4 | Touch MA 4", "{{ticker}} {{interval}} {{close}} — Ribbon: 觸碰均線 4 | Price touched MA 4")
alertcondition(_alVs, "◆ 觸碰維加斯 144/169 | Touch Vegas 144/169", "{{ticker}} {{interval}} {{close}} — Ribbon: 觸碰維加斯 144/169 通道 | Price touched Vegas 144/169 channel")
alertcondition(_alVl, "◆ 觸碰維加斯 576/676 | Touch Vegas 576/676", "{{ticker}} {{interval}} {{close}} — Ribbon: 觸碰維加斯 576/676 通道 | Price touched Vegas 576/676 channel")
f_alert(_alM1, "觸碰均線 1", "Price touched MA 1")
f_alert(_alM2, "觸碰均線 2", "Price touched MA 2")
f_alert(_alM3, "觸碰均線 3", "Price touched MA 3")
f_alert(_alM4, "觸碰均線 4", "Price touched MA 4")
f_alert(_alVs, "觸碰維加斯 144/169 通道", "Price touched Vegas 144/169 channel")
f_alert(_alVl, "觸碰維加斯 576/676 通道", "Price touched Vegas 576/676 channel")