Ultra Scalper Pro V2 | ZLSMA + Chandelier Exit

GODSTARY · study · 582 行 · 点赞 1,184 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script™ source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Ultra Scalper Pro - ZLSMA + Chandelier Exit + Multi-Indicator Suite
 
//@version=5
indicator("Ultra Scalper Pro | ZLSMA + Chandelier Exit", shorttitle="USP", overlay=true, max_labels_count=500, max_lines_count=500)
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 1. GENERAL SETTINGS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
string GRP_GENERAL = "═══ GENERAL SETTINGS ═══"
i_showSignals      = input.bool(true, "📍 Show Entry Signals", group=GRP_GENERAL)
i_showLabels       = input.bool(true, "🏷️ Show Labels", group=GRP_GENERAL)
i_showBackground   = input.bool(true, "🎨 Show Background Color", group=GRP_GENERAL)
i_longEnabled      = input.bool(true, "🟢 Enable Long Signals", group=GRP_GENERAL)
i_shortEnabled     = input.bool(true, "🔴 Enable Short Signals", group=GRP_GENERAL)
i_showAlerts       = input.bool(true, "🔔 Enable Alerts", group=GRP_GENERAL)
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 2. ZLSMA SETTINGS (Zero Lag LSMA) ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
string GRP_ZLSMA = "═══ ZLSMA SETTINGS ═══"
i_useZLSMA        = input.bool(true, "✅ Use ZLSMA", group=GRP_ZLSMA)
i_zlsmaLength     = input.int(32, "📏 ZLSMA Length", minval=1, maxval=200, group=GRP_ZLSMA)
i_zlsmaOffset     = input.int(0, "➡️ ZLSMA Offset", minval=-50, maxval=50, group=GRP_ZLSMA)
i_zlsmaColorUp    = input.color(color.new(#00E676, 0), "🟢 Bullish Color", group=GRP_ZLSMA)
i_zlsmaColorDown  = input.color(color.new(#FF5252, 0), "🔴 Bearish Color", group=GRP_ZLSMA)
i_showZLSMA       = input.bool(true, "📊 Show ZLSMA Line", group=GRP_ZLSMA)
 
// ZLSMA Calculation (Zero Lag Least Squares Moving Average)
lsma(_src, _length) =>
    ta.linreg(_src, _length, 0)
 
zlsma_src = close
zlsma_lsma = lsma(zlsma_src, i_zlsmaLength)
zlsma_lsma2 = lsma(zlsma_lsma, i_zlsmaLength)
zlsma_eq = zlsma_lsma - zlsma_lsma2
zlsma_value = zlsma_lsma + zlsma_eq
 
zlsma_color = zlsma_value > zlsma_value[1] ? i_zlsmaColorUp : i_zlsmaColorDown
plot(i_useZLSMA and i_showZLSMA ? zlsma_value : na, "ZLSMA", color=zlsma_color, linewidth=2, offset=i_zlsmaOffset)
 
// ZLSMA Signals
zlsma_bullish = close > zlsma_value and close[1] <= zlsma_value[1]
zlsma_bearish = close < zlsma_value and close[1] >= zlsma_value[1]
zlsma_trend_up = close > zlsma_value
zlsma_trend_down = close < zlsma_value
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 3. CHANDELIER EXIT SETTINGS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
string GRP_CHANDELIER = "═══ CHANDELIER EXIT SETTINGS ═══"
i_useChandelier    = input.bool(true, "✅ Use Chandelier Exit", group=GRP_CHANDELIER)
i_ceLength         = input.int(22, "📏 ATR Period", minval=1, maxval=100, group=GRP_CHANDELIER)
i_ceMult           = input.float(3.0, "✖️ ATR Multiplier", minval=0.5, maxval=10.0, step=0.1, group=GRP_CHANDELIER)
i_ceShowLabels     = input.bool(true, "🏷️ Show CE Labels", group=GRP_CHANDELIER)
i_ceHighlightState = input.bool(true, "🔦 Highlight Trend State", group=GRP_CHANDELIER)
i_ceColorBull      = input.color(color.new(#00E676, 0), "🟢 Bullish Color", group=GRP_CHANDELIER)
i_ceColorBear      = input.color(color.new(#FF5252, 0), "🔴 Bearish Color", group=GRP_CHANDELIER)
i_showChandelier   = input.bool(true, "📊 Show Chandelier Line", group=GRP_CHANDELIER)
 
// Chandelier Exit Calculation
ce_atr = ta.atr(i_ceLength)
 
ce_longStop = ta.highest(high, i_ceLength) - ce_atr * i_ceMult
ce_longStopPrev = nz(ce_longStop[1], ce_longStop)
ce_longStop := close[1] > ce_longStopPrev ? math.max(ce_longStop, ce_longStopPrev) : ce_longStop
 
ce_shortStop = ta.lowest(low, i_ceLength) + ce_atr * i_ceMult
ce_shortStopPrev = nz(ce_shortStop[1], ce_shortStop)
ce_shortStop := close[1] < ce_shortStopPrev ? math.min(ce_shortStop, ce_shortStopPrev) : ce_shortStop
 
var int ce_dir = 1
ce_dir := close > ce_shortStopPrev ? 1 : close < ce_longStopPrev ? -1 : ce_dir
 
ce_value = ce_dir == 1 ? ce_longStop : ce_shortStop
 
// Chandelier Colors & Plots
ce_plotColor = ce_dir == 1 ? i_ceColorBull : i_ceColorBear
plot(i_useChandelier and i_showChandelier ? ce_value : na, "Chandelier Exit", color=ce_plotColor, linewidth=2, style=plot.style_linebr)
 
// Chandelier Signals
ce_buySignal = ce_dir == 1 and ce_dir[1] == -1
ce_sellSignal = ce_dir == -1 and ce_dir[1] == 1
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 4. RSI FILTER SETTINGS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
string GRP_RSI = "═══ RSI FILTER SETTINGS ═══"
i_useRSI           = input.bool(true, "✅ Use RSI Filter", group=GRP_RSI)
i_rsiLength        = input.int(14, "📏 RSI Period", minval=1, maxval=100, group=GRP_RSI)
i_rsiOverbought    = input.int(70, "⬆️ Overbought Level", minval=50, maxval=100, group=GRP_RSI)
i_rsiOversold      = input.int(30, "⬇️ Oversold Level", minval=0, maxval=50, group=GRP_RSI)
i_rsiMidLine       = input.int(50, "➖ Midline", minval=30, maxval=70, group=GRP_RSI)
 
// RSI Calculation
rsi_value = ta.rsi(close, i_rsiLength)
 
// RSI Conditions
rsi_bullish = i_useRSI ? rsi_value > i_rsiMidLine and rsi_value < i_rsiOverbought : true
rsi_bearish = i_useRSI ? rsi_value < i_rsiMidLine and rsi_value > i_rsiOversold : true
rsi_neutral = i_useRSI ? rsi_value >= i_rsiOversold and rsi_value <= i_rsiOverbought : true
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 5. VOLUME FILTER SETTINGS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
string GRP_VOLUME = "═══ VOLUME FILTER SETTINGS ═══"
i_useVolume        = input.bool(true, "✅ Use Volume Filter", group=GRP_VOLUME)
i_volumeLength     = input.int(20, "📏 Volume MA Period", minval=1, maxval=100, group=GRP_VOLUME)
i_volumeMult       = input.float(1.0, "✖️ Volume Multiplier", minval=0.5, maxval=5.0, step=0.1, group=GRP_VOLUME)
 
// Volume Calculation
vol_ma = ta.sma(volume, i_volumeLength)
vol_condition = i_useVolume ? volume > vol_ma * i_volumeMult : true
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 6. EMA TREND FILTER SETTINGS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
string GRP_EMA = "═══ EMA TREND FILTER SETTINGS ═══"
i_useEMA           = input.bool(true, "✅ Use EMA Filter", group=GRP_EMA)
i_emaFastLength    = input.int(9, "📏 Fast EMA Period", minval=1, maxval=100, group=GRP_EMA)
i_emaSlowLength    = input.int(21, "📏 Slow EMA Period", minval=1, maxval=200, group=GRP_EMA)
i_showEMA          = input.bool(false, "📊 Show EMA Lines", group=GRP_EMA)
i_emaFastColor     = input.color(color.new(#2196F3, 50), "🔵 Fast EMA Color", group=GRP_EMA)
i_emaSlowColor     = input.color(color.new(#FF9800, 50), "🟠 Slow EMA Color", group=GRP_EMA)
 
// EMA Calculation
ema_fast = ta.ema(close, i_emaFastLength)
ema_slow = ta.ema(close, i_emaSlowLength)
 
plot(i_useEMA and i_showEMA ? ema_fast : na, "Fast EMA", color=i_emaFastColor, linewidth=1)
plot(i_useEMA and i_showEMA ? ema_slow : na, "Slow EMA", color=i_emaSlowColor, linewidth=1)
 
// EMA Conditions
ema_bullish = i_useEMA ? ema_fast > ema_slow : true
ema_bearish = i_useEMA ? ema_fast < ema_slow : true
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 7. SUPERTREND CONFIRMATION SETTINGS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
string GRP_ST = "═══ SUPERTREND SETTINGS ═══"
i_useSuperTrend    = input.bool(false, "✅ Use SuperTrend", group=GRP_ST)
i_stLength         = input.int(10, "📏 SuperTrend Period", minval=1, maxval=100, group=GRP_ST)
i_stMult           = input.float(2.0, "✖️ SuperTrend Multiplier", minval=0.5, maxval=10.0, step=0.1, group=GRP_ST)
i_showSuperTrend   = input.bool(true, "📊 Show SuperTrend Line", group=GRP_ST)
 
// SuperTrend Calculation
[st_value, st_dir] = ta.supertrend(i_stMult, i_stLength)
 
st_color = st_dir < 0 ? color.new(#00E676, 20) : color.new(#FF5252, 20)
plot(i_useSuperTrend and i_showSuperTrend ? st_value : na, "SuperTrend", color=st_color, linewidth=2, style=plot.style_linebr)
 
// SuperTrend Conditions
st_bullish = i_useSuperTrend ? st_dir < 0 : true
st_bearish = i_useSuperTrend ? st_dir > 0 : true
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 8. MACD CONFIRMATION SETTINGS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
string GRP_MACD = "═══ MACD SETTINGS ═══"
i_useMACD          = input.bool(false, "✅ Use MACD Confirmation", group=GRP_MACD)
i_macdFast         = input.int(12, "📏 Fast Period", minval=1, maxval=100, group=GRP_MACD)
i_macdSlow         = input.int(26, "📏 Slow Period", minval=1, maxval=100, group=GRP_MACD)
i_macdSignal       = input.int(9, "📏 Signal Period", minval=1, maxval=100, group=GRP_MACD)
 
// MACD Calculation
[macdLine, signalLine, histLine] = ta.macd(close, i_macdFast, i_macdSlow, i_macdSignal)
 
// MACD Conditions
macd_bullish = i_useMACD ? macdLine > signalLine : true
macd_bearish = i_useMACD ? macdLine < signalLine : true
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 9. STOCHASTIC SETTINGS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
string GRP_STOCH = "═══ STOCHASTIC SETTINGS ═══"
i_useStoch         = input.bool(false, "✅ Use Stochastic", group=GRP_STOCH)
i_stochK           = input.int(14, "📏 K Period", minval=1, maxval=100, group=GRP_STOCH)
i_stochD           = input.int(3, "📏 D Period", minval=1, maxval=100, group=GRP_STOCH)
i_stochSmooth      = input.int(3, "📏 Smoothing", minval=1, maxval=100, group=GRP_STOCH)
i_stochOB          = input.int(80, "⬆️ Overbought", minval=50, maxval=100, group=GRP_STOCH)
i_stochOS          = input.int(20, "⬇️ Oversold", minval=0, maxval=50, group=GRP_STOCH)
 
// Stochastic Calculation
stoch_k = ta.sma(ta.stoch(close, high, low, i_stochK), i_stochSmooth)
stoch_d = ta.sma(stoch_k, i_stochD)
 
// Stochastic Conditions
stoch_bullish = i_useStoch ? stoch_k > stoch_d and stoch_k < i_stochOB : true
stoch_bearish = i_useStoch ? stoch_k < stoch_d and stoch_k > i_stochOS : true
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 10. ATR-BASED TP/SL SETTINGS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
string GRP_TPSL = "═══ TP/SL SETTINGS ═══"
i_showTPSL         = input.bool(true, "📊 Show TP/SL Levels", group=GRP_TPSL)
i_tpslMode         = input.string("ATR Based", "📐 TP/SL Mode", options=["ATR Based", "Fixed %", "R:R Ratio", "Chandelier Based"], group=GRP_TPSL)
i_atrLengthTPSL    = input.int(14, "📏 ATR Period (TP/SL)", minval=1, maxval=100, group=GRP_TPSL)
 
// ATR-Based Settings
i_slMultATR        = input.float(1.5, "🛑 SL ATR Multiplier", minval=0.5, maxval=10.0, step=0.1, group=GRP_TPSL)
i_tp1MultATR       = input.float(1.0, "🎯 TP1 ATR Multiplier", minval=0.5, maxval=10.0, step=0.1, group=GRP_TPSL)
i_tp2MultATR       = input.float(2.0, "🎯 TP2 ATR Multiplier", minval=0.5, maxval=20.0, step=0.1, group=GRP_TPSL)
i_tp3MultATR       = input.float(3.0, "🎯 TP3 ATR Multiplier", minval=0.5, maxval=30.0, step=0.1, group=GRP_TPSL)
 
// Fixed Percentage Settings
i_slPercent        = input.float(1.0, "🛑 SL % (Fixed)", minval=0.1, maxval=10.0, step=0.1, group=GRP_TPSL)
i_tp1Percent       = input.float(0.5, "🎯 TP1 % (Fixed)", minval=0.1, maxval=10.0, step=0.1, group=GRP_TPSL)
i_tp2Percent       = input.float(1.0, "🎯 TP2 % (Fixed)", minval=0.1, maxval=20.0, step=0.1, group=GRP_TPSL)
i_tp3Percent       = input.float(1.5, "🎯 TP3 % (Fixed)", minval=0.1, maxval=30.0, step=0.1, group=GRP_TPSL)
 
// Risk:Reward Settings
i_rrRatio          = input.float(2.0, "📊 R:R Ratio", minval=1.0, maxval=10.0, step=0.5, group=GRP_TPSL)
 
// ATR for TP/SL
atr_tpsl = ta.atr(i_atrLengthTPSL)
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 11. SESSION FILTER SETTINGS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
string GRP_SESSION = "═══ SESSION FILTER SETTINGS ═══"
i_useSessionFilter = input.bool(false, "✅ Use Session Filter", group=GRP_SESSION)
i_asiaSession      = input.session("0000-0800", "🌏 Asia Session", group=GRP_SESSION)
i_euroSession      = input.session("0700-1600", "🌍 Europe Session", group=GRP_SESSION)
i_usSession        = input.session("1300-2200", "🌎 US Session", group=GRP_SESSION)
i_activeSession    = input.string("All", "Active Session", options=["All", "Asia", "Europe", "US", "Asia+Europe", "Europe+US"], group=GRP_SESSION)
 
// Session Check Function
isInSession(_session) =>
    not na(time(timeframe.period, _session))
 
asiaActive = isInSession(i_asiaSession)
euroActive = isInSession(i_euroSession)
usActive = isInSession(i_usSession)
 
sessionActive = switch i_activeSession
    "All" => true
    "Asia" => asiaActive
    "Europe" => euroActive
    "US" => usActive
    "Asia+Europe" => asiaActive or euroActive
    "Europe+US" => euroActive or usActive
    => true
 
sessionCondition = i_useSessionFilter ? sessionActive : true
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 12. ENTRY SIGNAL LOGIC ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
// Primary Signals (ZLSMA + Chandelier)
zlsma_long_cond = i_useZLSMA ? (zlsma_bullish or zlsma_trend_up) : true
ce_long_cond = i_useChandelier ? (ce_buySignal or ce_dir == 1) : true
primary_long = zlsma_long_cond and ce_long_cond
 
zlsma_short_cond = i_useZLSMA ? (zlsma_bearish or zlsma_trend_down) : true
ce_short_cond = i_useChandelier ? (ce_sellSignal or ce_dir == -1) : true
primary_short = zlsma_short_cond and ce_short_cond
 
// Confirmation Filters
confirm_long = ema_bullish and rsi_bullish and vol_condition and st_bullish and macd_bullish and stoch_bullish and sessionCondition
confirm_short = ema_bearish and rsi_bearish and vol_condition and st_bearish and macd_bearish and stoch_bearish and sessionCondition
 
// Final Entry Signals
long_signal = primary_long and confirm_long and i_longEnabled
short_signal = primary_short and confirm_short and i_shortEnabled
 
// Strong Signal Detection (for visual emphasis)
strong_long = (i_useZLSMA and zlsma_bullish) and (i_useChandelier and ce_buySignal) and vol_condition
strong_short = (i_useZLSMA and zlsma_bearish) and (i_useChandelier and ce_sellSignal) and vol_condition
 
// Trigger Signals (exact entry point)
trigger_long = long_signal and (zlsma_bullish or ce_buySignal)
trigger_short = short_signal and (zlsma_bearish or ce_sellSignal)
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 13. CALCULATE TP/SL LEVELS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
// Variables for TP/SL tracking
var float entry_price = na
var float sl_price = na
var float tp1_price = na
var float tp2_price = na
var float tp3_price = na
var bool is_long = na
var bool in_position = false
 
// Calculate levels based on mode
calcLongLevels(_entry) =>
    float _sl = na
    float _tp1 = na
    float _tp2 = na
    float _tp3 = na
    
    if i_tpslMode == "ATR Based"
        _sl := _entry - atr_tpsl * i_slMultATR
        _tp1 := _entry + atr_tpsl * i_tp1MultATR
        _tp2 := _entry + atr_tpsl * i_tp2MultATR
        _tp3 := _entry + atr_tpsl * i_tp3MultATR
    else if i_tpslMode == "Fixed %"
        _sl := _entry * (1 - i_slPercent / 100)
        _tp1 := _entry * (1 + i_tp1Percent / 100)
        _tp2 := _entry * (1 + i_tp2Percent / 100)
        _tp3 := _entry * (1 + i_tp3Percent / 100)
    else if i_tpslMode == "R:R Ratio"
        slDist = atr_tpsl * i_slMultATR
        _sl := _entry - slDist
        _tp1 := _entry + slDist * i_rrRatio * 0.5
        _tp2 := _entry + slDist * i_rrRatio
        _tp3 := _entry + slDist * i_rrRatio * 1.5
    else if i_tpslMode == "Chandelier Based"
        _sl := ce_longStop
        slDist = math.abs(_entry - _sl)
        _tp1 := _entry + slDist * 1.0
        _tp2 := _entry + slDist * 2.0
        _tp3 := _entry + slDist * 3.0
    
    [_sl, _tp1, _tp2, _tp3]
 
calcShortLevels(_entry) =>
    float _sl = na
    float _tp1 = na
    float _tp2 = na
    float _tp3 = na
    
    if i_tpslMode == "ATR Based"
        _sl := _entry + atr_tpsl * i_slMultATR
        _tp1 := _entry - atr_tpsl * i_tp1MultATR
        _tp2 := _entry - atr_tpsl * i_tp2MultATR
        _tp3 := _entry - atr_tpsl * i_tp3MultATR
    else if i_tpslMode == "Fixed %"
        _sl := _entry * (1 + i_slPercent / 100)
        _tp1 := _entry * (1 - i_tp1Percent / 100)
        _tp2 := _entry * (1 - i_tp2Percent / 100)
        _tp3 := _entry * (1 - i_tp3Percent / 100)
    else if i_tpslMode == "R:R Ratio"
        slDist = atr_tpsl * i_slMultATR
        _sl := _entry + slDist
        _tp1 := _entry - slDist * i_rrRatio * 0.5
        _tp2 := _entry - slDist * i_rrRatio
        _tp3 := _entry - slDist * i_rrRatio * 1.5
    else if i_tpslMode == "Chandelier Based"
        _sl := ce_shortStop
        slDist = math.abs(_entry - _sl)
        _tp1 := _entry - slDist * 1.0
        _tp2 := _entry - slDist * 2.0
        _tp3 := _entry - slDist * 3.0
    
    [_sl, _tp1, _tp2, _tp3]
 
// Track position and levels
if trigger_long and not in_position
    entry_price := close
    is_long := true
    in_position := true
    [_sl, _tp1, _tp2, _tp3] = calcLongLevels(close)
    sl_price := _sl
    tp1_price := _tp1
    tp2_price := _tp2
    tp3_price := _tp3
 
if trigger_short and not in_position
    entry_price := close
    is_long := false
    in_position := true
    [_sl, _tp1, _tp2, _tp3] = calcShortLevels(close)
    sl_price := _sl
    tp1_price := _tp1
    tp2_price := _tp2
    tp3_price := _tp3
 
// Check for exit conditions
if in_position
    if is_long
        if low <= sl_price or high >= tp3_price
            in_position := false
        if trigger_short
            in_position := false
    else
        if high >= sl_price or low <= tp3_price
            in_position := false
        if trigger_long
            in_position := false
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 14. VISUAL SIGNALS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
// Entry Signals - Strong
plotshape(i_showSignals and trigger_long and strong_long ? low : na, "Strong Long", shape.triangleup, location.belowbar, color.new(#00E676, 0), size=size.normal)
plotshape(i_showSignals and trigger_short and strong_short ? high : na, "Strong Short", shape.triangledown, location.abovebar, color.new(#FF5252, 0), size=size.normal)
 
// Entry Signals - Normal
plotshape(i_showSignals and trigger_long and not strong_long ? low : na, "Normal Long", shape.triangleup, location.belowbar, color.new(#00E676, 40), size=size.small)
plotshape(i_showSignals and trigger_short and not strong_short ? high : na, "Normal Short", shape.triangledown, location.abovebar, color.new(#FF5252, 40), size=size.small)
 
// Chandelier Exit Signals
plotshape(i_showSignals and i_ceShowLabels and ce_buySignal ? ce_longStop : na, "CE Buy", shape.circle, location.absolute, i_ceColorBull, size=size.tiny)
plotshape(i_showSignals and i_ceShowLabels and ce_sellSignal ? ce_shortStop : na, "CE Sell", shape.circle, location.absolute, i_ceColorBear, size=size.tiny)
 
// Background Color for Position
var color bgcolor_pos = na
if i_showBackground
    if in_position and is_long
        bgcolor_pos := color.new(#00E676, 92)
    else if in_position and not is_long
        bgcolor_pos := color.new(#FF5252, 92)
    else
        bgcolor_pos := na
else
    bgcolor_pos := na
bgcolor(bgcolor_pos, title="Position Background")
 
// Trend Background
var color trend_bg = na
if i_showBackground and i_ceHighlightState and not in_position
    trend_bg := ce_dir == 1 ? color.new(#00E676, 96) : color.new(#FF5252, 96)
else
    trend_bg := na
bgcolor(trend_bg, title="Trend Background")
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 15. TP/SL LEVEL PLOTS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
plot(i_showTPSL and in_position ? entry_price : na, "Entry Price", color.new(color.yellow, 0), 1, plot.style_linebr)
plot(i_showTPSL and in_position ? sl_price : na, "Stop Loss", color.new(color.red, 0), 2, plot.style_linebr)
plot(i_showTPSL and in_position ? tp1_price : na, "TP1", color.new(#4CAF50, 50), 1, plot.style_linebr)
plot(i_showTPSL and in_position ? tp2_price : na, "TP2", color.new(#4CAF50, 30), 1, plot.style_linebr)
plot(i_showTPSL and in_position ? tp3_price : na, "TP3", color.new(#4CAF50, 0), 2, plot.style_linebr)
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 16. LABELS FOR TP/SL ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
if i_showLabels and i_showTPSL and trigger_long
    label.new(bar_index, tp3_price, "TP3: " + str.tostring(tp3_price, "#.##"), style=label.style_label_down, color=color.new(#4CAF50, 20), textcolor=color.white, size=size.tiny)
    label.new(bar_index, tp2_price, "TP2: " + str.tostring(tp2_price, "#.##"), style=label.style_label_down, color=color.new(#4CAF50, 40), textcolor=color.white, size=size.tiny)
    label.new(bar_index, tp1_price, "TP1: " + str.tostring(tp1_price, "#.##"), style=label.style_label_down, color=color.new(#4CAF50, 60), textcolor=color.white, size=size.tiny)
    label.new(bar_index, entry_price, "ENTRY: " + str.tostring(entry_price, "#.##"), style=label.style_label_left, color=color.new(color.yellow, 20), textcolor=color.black, size=size.tiny)
    label.new(bar_index, sl_price, "SL: " + str.tostring(sl_price, "#.##"), style=label.style_label_up, color=color.new(color.red, 20), textcolor=color.white, size=size.tiny)
 
if i_showLabels and i_showTPSL and trigger_short
    label.new(bar_index, tp3_price, "TP3: " + str.tostring(tp3_price, "#.##"), style=label.style_label_up, color=color.new(#4CAF50, 20), textcolor=color.white, size=size.tiny)
    label.new(bar_index, tp2_price, "TP2: " + str.tostring(tp2_price, "#.##"), style=label.style_label_up, color=color.new(#4CAF50, 40), textcolor=color.white, size=size.tiny)
    label.new(bar_index, tp1_price, "TP1: " + str.tostring(tp1_price, "#.##"), style=label.style_label_up, color=color.new(#4CAF50, 60), textcolor=color.white, size=size.tiny)
    label.new(bar_index, entry_price, "ENTRY: " + str.tostring(entry_price, "#.##"), style=label.style_label_left, color=color.new(color.yellow, 20), textcolor=color.black, size=size.tiny)
    label.new(bar_index, sl_price, "SL: " + str.tostring(sl_price, "#.##"), style=label.style_label_down, color=color.new(color.red, 20), textcolor=color.white, size=size.tiny)
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 17. INFO TABLE ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
string GRP_TABLE = "═══ INFO TABLE SETTINGS ═══"
i_showTable = input.bool(true, "📊 Show Info Table", group=GRP_TABLE)
i_tablePos = input.string("top_right", "📍 Table Position", options=["top_right", "top_left", "bottom_right", "bottom_left"], group=GRP_TABLE)
i_tableSize = input.string("small", "📏 Table Size", options=["tiny", "small", "normal"], group=GRP_TABLE)
 
tablePosition = switch i_tablePos
    "top_right" => position.top_right
    "top_left" => position.top_left
    "bottom_right" => position.bottom_right
    "bottom_left" => position.bottom_left
    => position.top_right
 
tableSize = switch i_tableSize
    "tiny" => size.tiny
    "small" => size.small
    "normal" => size.normal
    => size.small
 
var table infoTable = table.new(tablePosition, 2, 14, bgcolor=color.new(#1E1E1E, 10), border_width=1, border_color=color.new(color.gray, 50))
 
if barstate.islast and i_showTable
    // Header
    table.cell(infoTable, 0, 0, "📊 INDICATOR", text_color=color.white, text_size=tableSize, bgcolor=color.new(#333333, 0))
    table.cell(infoTable, 1, 0, "STATUS", text_color=color.white, text_size=tableSize, bgcolor=color.new(#333333, 0))
    
    // ZLSMA Status
    zlsmaStatus = zlsma_trend_up ? "🟢 BULLISH" : "🔴 BEARISH"
    zlsmaCol = zlsma_trend_up ? color.green : color.red
    table.cell(infoTable, 0, 1, "ZLSMA", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 1, i_useZLSMA ? zlsmaStatus : "OFF", text_color=i_useZLSMA ? zlsmaCol : color.gray, text_size=tableSize)
    
    // Chandelier Status
    ceStatus = ce_dir == 1 ? "🟢 LONG" : "🔴 SHORT"
    ceCol = ce_dir == 1 ? color.green : color.red
    table.cell(infoTable, 0, 2, "Chandelier", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 2, i_useChandelier ? ceStatus : "OFF", text_color=i_useChandelier ? ceCol : color.gray, text_size=tableSize)
    
    // RSI Status
    rsiText = str.tostring(rsi_value, "#.#")
    rsiStatus = rsi_value > i_rsiOverbought ? "⚠️ OB" : rsi_value < i_rsiOversold ? "⚠️ OS" : "✅ OK"
    table.cell(infoTable, 0, 3, "RSI", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 3, i_useRSI ? rsiText + " " + rsiStatus : "OFF", text_color=color.white, text_size=tableSize)
    
    // Volume Status
    volStatus = vol_condition ? "✅ HIGH" : "⚠️ LOW"
    volCol = vol_condition ? color.green : color.orange
    table.cell(infoTable, 0, 4, "Volume", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 4, i_useVolume ? volStatus : "OFF", text_color=i_useVolume ? volCol : color.gray, text_size=tableSize)
    
    // EMA Status
    emaStatus = ema_bullish ? "🟢 BULLISH" : "🔴 BEARISH"
    emaCol = ema_bullish ? color.green : color.red
    table.cell(infoTable, 0, 5, "EMA Cross", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 5, i_useEMA ? emaStatus : "OFF", text_color=i_useEMA ? emaCol : color.gray, text_size=tableSize)
    
    // SuperTrend Status
    stStatus = st_bullish ? "🟢 BULLISH" : "🔴 BEARISH"
    stCol = st_bullish ? color.green : color.red
    table.cell(infoTable, 0, 6, "SuperTrend", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 6, i_useSuperTrend ? stStatus : "OFF", text_color=i_useSuperTrend ? stCol : color.gray, text_size=tableSize)
    
    // MACD Status
    macdStatus = macd_bullish ? "🟢 BULLISH" : "🔴 BEARISH"
    macdCol = macd_bullish ? color.green : color.red
    table.cell(infoTable, 0, 7, "MACD", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 7, i_useMACD ? macdStatus : "OFF", text_color=i_useMACD ? macdCol : color.gray, text_size=tableSize)
    
    // Stochastic Status
    stochStatus = stoch_bullish ? "🟢 BULLISH" : "🔴 BEARISH"
    stochCol = stoch_bullish ? color.green : color.red
    table.cell(infoTable, 0, 8, "Stochastic", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 8, i_useStoch ? stochStatus : "OFF", text_color=i_useStoch ? stochCol : color.gray, text_size=tableSize)
    
    // Separator
    table.cell(infoTable, 0, 9, "─────────", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 9, "─────────", text_color=color.gray, text_size=tableSize)
    
    // ATR Value
    table.cell(infoTable, 0, 10, "ATR", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 10, str.tostring(atr_tpsl, "#.###"), text_color=color.white, text_size=tableSize)
    
    // Position Status
    posStatus = in_position ? (is_long ? "🟢 LONG" : "🔴 SHORT") : "⚪ NONE"
    posCol = in_position ? (is_long ? color.green : color.red) : color.gray
    table.cell(infoTable, 0, 11, "Position", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 11, posStatus, text_color=posCol, text_size=tableSize)
    
    // Entry Price
    table.cell(infoTable, 0, 12, "Entry", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 12, in_position ? str.tostring(entry_price, "#.##") : "-", text_color=color.yellow, text_size=tableSize)
    
    // Current P&L
    pnl = in_position ? (close - entry_price) / entry_price * 100 * (is_long ? 1 : -1) : 0.0
    pnlCol = pnl > 0 ? color.green : pnl < 0 ? color.red : color.gray
    pnlText = in_position ? str.tostring(pnl, "#.##") + "%" : "-"
    table.cell(infoTable, 0, 13, "P&L", text_color=color.gray, text_size=tableSize)
    table.cell(infoTable, 1, 13, pnlText, text_color=pnlCol, text_size=tableSize)
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ 18. ALERTS ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════
 
alertcondition(trigger_long, "🟢 Long Signal", "Ultra Scalper Pro: Long Entry Signal!")
alertcondition(trigger_short, "🔴 Short Signal", "Ultra Scalper Pro: Short Entry Signal!")
alertcondition(strong_long, "💚 Strong Long", "Ultra Scalper Pro: Strong Long Signal!")
alertcondition(strong_short, "❤️ Strong Short", "Ultra Scalper Pro: Strong Short Signal!")
alertcondition(ce_buySignal, "CE Buy Signal", "Chandelier Exit: Buy Signal Triggered")
alertcondition(ce_sellSignal, "CE Sell Signal", "Chandelier Exit: Sell Signal Triggered")
alertcondition(zlsma_bullish, "ZLSMA Bullish Cross", "ZLSMA: Price crossed above")
alertcondition(zlsma_bearish, "ZLSMA Bearish Cross", "ZLSMA: Price crossed below")
 
// Compound Alerts
alertcondition(trigger_long or trigger_short, "Any Entry Signal", "Ultra Scalper Pro: Entry Signal Detected!")
alertcondition(strong_long or strong_short, "Any Strong Signal", "Ultra Scalper Pro: Strong Signal Detected!")
 
// ═══════════════════════════════════════════════════════════════════════════════
// ▓▓▓ END OF SCRIPT ▓▓▓
// ═══════════════════════════════════════════════════════════════════════════════

← 返回列表