本页源码来自 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/
// © joses2777
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © joses2777
//@version=6
indicator('EMA 9/21/50 + VWAP + MACD + RSI Pro [v6]', overlay=true, precision=2, max_lines_count=500)
// ———————— Inputs ————————
// EMA Settings
ema9_len = input.int(9, 'EMA 9 Length', group='Moving Averages', minval=1)
ema21_len = input.int(21, 'EMA 21 Length', group='Moving Averages', minval=1)
ema50_len = input.int(50, 'EMA 50 Length', group='Moving Averages', minval=1)
// MACD Settings
macd_fast = input.int(12, 'MACD Fast Length', group='MACD', minval=1)
macd_slow = input.int(26, 'MACD Slow Length', group='MACD', minval=1)
macd_signal = input.int(9, 'MACD Signal Length', group='MACD', minval=1)
// RSI Settings
rsi_length = input.int(14, 'RSI Length', group='RSI', minval=1)
rsi_overbought = input.int(70, 'RSI Overbought', group='RSI', minval=50, maxval=90)
rsi_oversold = input.int(30, 'RSI Oversold', group='RSI', minval=10, maxval=50)
// Style Settings
ema9_color = input.color(#2962FF, 'EMA 9 Color', group='Style')
ema21_color = input.color(#FF6D00, 'EMA 21 Color', group='Style')
ema50_color = input.color(#00C853, 'EMA 50 Color', group='Style')
vwap_color = input.color(#AA00FF, 'VWAP Color', group='Style')
rsi_color = input.color(#FFC400, 'RSI Color', group='Style')
// Alert Settings
show_alerts = input.bool(true, 'Enable Alerts', group='Alerts')
// ———————— Calculations ————————
// EMAs
ema9 = ta.ema(close, ema9_len)
ema21 = ta.ema(close, ema21_len)
ema50 = ta.ema(close, ema50_len)
// VWAP (intraday only)
varip vwap_value = ta.vwap(hlc3)
is_new_day = ta.change(time('D')) != 0
// Enhanced MACD
[macdLine, signalLine, histLine] = ta.macd(close, macd_fast, macd_slow, macd_signal)
macd_above_zero = macdLine >= 0
macd_bullish = histLine > 0 and histLine > histLine[1] and macd_above_zero
macd_bearish = histLine < 0 and histLine < histLine[1] and not macd_above_zero
// RSI Calculation
rsi_value = ta.rsi(close, rsi_length)
rsi_bullish = rsi_value > rsi_oversold and rsi_value[1] <= rsi_oversold
rsi_bearish = rsi_value < rsi_overbought and rsi_value[1] >= rsi_overbought
// Trend Conditions
bullish_trend = ema9 > ema21 and ema21 > ema50 and close > ema50
bearish_trend = ema9 < ema21 and ema21 < ema50 and close < ema50
// Signal Conditions with RSI confirmation
bullish_signal = show_alerts and bullish_trend and ta.crossover(ema9, ema21) and macd_bullish and (close > vwap_value or not is_new_day) and rsi_bullish
bearish_signal = show_alerts and bearish_trend and ta.crossunder(ema9, ema21) and macd_bearish and (close < vwap_value or not is_new_day) and rsi_bearish
// ———————— Plots ————————
plot(ema9, 'EMA 9', ema9_color, 2, trackprice=true)
plot(ema21, 'EMA 21', ema21_color, 2, trackprice=true)
plot(ema50, 'EMA 50', ema50_color, 2, trackprice=true)
plot(not is_new_day ? vwap_value : na, 'VWAP', vwap_color, 2, style=plot.style_linebr)
// RSI Plot in Separate Pane
plot(rsi_value, 'RSI', color=rsi_color)
hline(rsi_overbought, 'Overbought', color=color.rgb(252, 57, 57), linestyle=hline.style_dotted)
hline(rsi_oversold, 'Oversold', color=color.rgb(85, 247, 90), linestyle=hline.style_dotted)
// ———————— Visual Signals ————————
bgcolor(bullish_trend ? color.new(color.green, 85) : bearish_trend ? color.new(color.red, 85) : na)
plotshape(bullish_signal, '↑', shape.labelup, location.belowbar, color.green, text='🟢', textcolor=color.white, size=size.large)
plotshape(bearish_signal, '↓', shape.labeldown, location.abovebar, color.red, text='🔴', textcolor=color.white, size=size.large)
macd_signal_up = macdLine > signalLine
plotshape(macd_signal_up and not macd_signal_up[1], 'MACD↑', shape.labelup, location.bottom, color.teal, textcolor=color.white, size=size.small)
plotshape(not macd_signal_up and macd_signal_up[1], 'MACD↓', shape.labeldown, location.top, color.orange, textcolor=color.white, size=size.small)
// RSI Signals
plotshape(rsi_bullish and not bullish_signal, 'RSI↑', shape.triangleup, location.bottom, color.lime, size=size.small)
plotshape(rsi_bearish and not bearish_signal, 'RSI↓', shape.triangledown, location.top, color.fuchsia, size=size.small)
// ———————— Alerts ————————
alertcondition(bullish_signal, 'Bullish Entry', 'EMA9>21, MACD↑, RSI↑, Price strong')
alertcondition(bearish_signal, 'Bearish Entry', 'EMA9<21, MACD↓, RSI↓, Price weak')
// ———————— Dashboard ————————
var table signalTable = table.new(position.top_right, 2, 6, border_width=2, frame_color=color.gray)
if barstate.islastconfirmedhistory
// Header row
table.cell(signalTable, 0, 0, "SYSTEM STATUS", bgcolor=color.blue, text_color=color.white)
table.cell(signalTable, 1, 0, "", bgcolor=color.blue)
// Trend Row
table.cell(signalTable, 0, 1, 'Trend', bgcolor=color.gray, text_color=color.white)
table.cell(signalTable, 1, 1, bullish_trend ? 'BULLISH' : bearish_trend ? 'BEARISH' : 'NEUTRAL',
bgcolor=bullish_trend ? color.green : bearish_trend ? color.red : color.gray,
text_color=color.white)
// EMA Row
table.cell(signalTable, 0, 2, 'EMA Cross', bgcolor=color.gray, text_color=color.white)
table.cell(signalTable, 1, 2, ema9 > ema21 ? 'EMA9 > 21' : 'EMA9 < 21',
bgcolor=ema9 > ema21 ? color.green : color.red,
text_color=color.white)
// MACD Row
table.cell(signalTable, 0, 3, 'MACD', bgcolor=color.gray, text_color=color.white)
table.cell(signalTable, 1, 3, macd_bullish ? 'BULLISH' : macd_bearish ? 'BEARISH' : 'NEUTRAL',
bgcolor=macd_bullish ? color.green : macd_bearish ? color.red : color.gray,
text_color=color.white)
// RSI Row
table.cell(signalTable, 0, 4, 'RSI', bgcolor=color.gray, text_color=color.white)
table.cell(signalTable, 1, 4, str.tostring(rsi_value, format.mintick) +
(rsi_value >= rsi_overbought ? " (OB)" : rsi_value <= rsi_oversold ? " (OS)" : ""),
bgcolor=rsi_value >= rsi_overbought ? color.red : rsi_value <= rsi_oversold ? color.green : color.gray,
text_color=color.white)
// VWAP Row
table.cell(signalTable, 0, 5, 'VWAP', bgcolor=color.gray, text_color=color.white)
table.cell(signalTable, 1, 5, close > vwap_value ? 'Price > VWAP' : 'Price < VWAP',
bgcolor=close > vwap_value ? color.green : color.red,
text_color=color.white)