OPEN-SOURCE SCRIPT
Vegas ema 過濾

Vegas Channel with EMA-Filter — Trading Rules
Components
Tunnel: EMA 144 & 169 (upper = max, lower = min).
Base: EMA 576 & 676 (upper = max, lower = min).
Fast filter: EMA12.
Touch threshold: ATR-based or % of the reference line.
Long touch = low ≤ line + thr; Short touch = high ≥ line − thr.
Trend gate
LongTrendOK: EMA144 > EMA576 and EMA169 > EMA676 and close > BaseUpper.
ShortTrendOK: EMA144 < EMA576 and EMA169 < EMA676 and close < BaseLower.
Price-action pattern (either one)
Pin40: bullish pin = close>open & lower wick ≥ 40% of range; bearish pin = close<open & upper wick ≥ 40%.
Eng60: bullish engulf = current green & previous red & body ≥ 60% of prev body; bearish symmetrical.
Touch logic (with auto switching)
LONG: require a lower-edge touch of the active band.
If EMA12 < 169 → use Base (576/676).
Else → use Tunnel (144/169).
SHORT: require an upper-edge touch of the active band.
If EMA12 > 169 → use Base.
Else → use Tunnel.
EMA12 hard locks (coarse filter)
Lock longs if EMA12 < 676 (no long signals at all).
Lock shorts if EMA12 > 676 (no short signals at all).
(Optional) Tunnel lock/unlock (fine filter)
Lock longs when EMA12 drops below TunnelLower; unlock when
A) EMA12 crosses back above 144/169/TunnelUpper, or
B) a bullish Pin/Eng appears at BaseUpper and EMA12 is back ≥ TunnelLower.
Lock shorts when EMA12 breaks above TunnelUpper; unlock when
A) EMA12 crosses back below 144/169/TunnelLower, or
B) a bearish Pin/Eng appears at BaseLower and EMA12 is ≤ TunnelUpper.
Final signal
LONG fires when: Close-bar confirmed ∧ Cooldown passed ∧ LongTrendOK ∧ ActiveBand lower touch ∧ Pin40 or Eng60 ∧ not hard-locked ∧ (not tunnel-locked if enabled).
SHORT symmetrical with upper touch.
Quality-of-life
Close-bar confirmation to avoid repaint.
Cooldown (e.g., 10 bars) to prevent signal clusters.
Alerts include a compact lock status string (LckL/LckS/HardL/HardS).
Optional “BLOCK:” labels show why a bar didn’t trigger (noTouch, EMA12<676/>676, TunnelLock, cooldown, notClose).
Suggested defaults
ATR(14), ATR multiplier 0.35 (or 0.20% if using Percent mode).
autoSwitchByEMA12_* = ON, hardLockBelow676/Above676 = ON, useTunnelLock* = OFF.
useCloseBar = ON, signalCooldown = 10.
Design intent
Tunnel (144/169) captures the working trend; Base (576/676) defines the structural bias.
EMA12 drives regime selection (Tunnel vs Base) and hard locks to keep signals sparse and aligned with momentum.
Components
Tunnel: EMA 144 & 169 (upper = max, lower = min).
Base: EMA 576 & 676 (upper = max, lower = min).
Fast filter: EMA12.
Touch threshold: ATR-based or % of the reference line.
Long touch = low ≤ line + thr; Short touch = high ≥ line − thr.
Trend gate
LongTrendOK: EMA144 > EMA576 and EMA169 > EMA676 and close > BaseUpper.
ShortTrendOK: EMA144 < EMA576 and EMA169 < EMA676 and close < BaseLower.
Price-action pattern (either one)
Pin40: bullish pin = close>open & lower wick ≥ 40% of range; bearish pin = close<open & upper wick ≥ 40%.
Eng60: bullish engulf = current green & previous red & body ≥ 60% of prev body; bearish symmetrical.
Touch logic (with auto switching)
LONG: require a lower-edge touch of the active band.
If EMA12 < 169 → use Base (576/676).
Else → use Tunnel (144/169).
SHORT: require an upper-edge touch of the active band.
If EMA12 > 169 → use Base.
Else → use Tunnel.
EMA12 hard locks (coarse filter)
Lock longs if EMA12 < 676 (no long signals at all).
Lock shorts if EMA12 > 676 (no short signals at all).
(Optional) Tunnel lock/unlock (fine filter)
Lock longs when EMA12 drops below TunnelLower; unlock when
A) EMA12 crosses back above 144/169/TunnelUpper, or
B) a bullish Pin/Eng appears at BaseUpper and EMA12 is back ≥ TunnelLower.
Lock shorts when EMA12 breaks above TunnelUpper; unlock when
A) EMA12 crosses back below 144/169/TunnelLower, or
B) a bearish Pin/Eng appears at BaseLower and EMA12 is ≤ TunnelUpper.
Final signal
LONG fires when: Close-bar confirmed ∧ Cooldown passed ∧ LongTrendOK ∧ ActiveBand lower touch ∧ Pin40 or Eng60 ∧ not hard-locked ∧ (not tunnel-locked if enabled).
SHORT symmetrical with upper touch.
Quality-of-life
Close-bar confirmation to avoid repaint.
Cooldown (e.g., 10 bars) to prevent signal clusters.
Alerts include a compact lock status string (LckL/LckS/HardL/HardS).
Optional “BLOCK:” labels show why a bar didn’t trigger (noTouch, EMA12<676/>676, TunnelLock, cooldown, notClose).
Suggested defaults
ATR(14), ATR multiplier 0.35 (or 0.20% if using Percent mode).
autoSwitchByEMA12_* = ON, hardLockBelow676/Above676 = ON, useTunnelLock* = OFF.
useCloseBar = ON, signalCooldown = 10.
Design intent
Tunnel (144/169) captures the working trend; Base (576/676) defines the structural bias.
EMA12 drives regime selection (Tunnel vs Base) and hard locks to keep signals sparse and aligned with momentum.
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。