本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Trend Dashboard - Intraday & Swing (Patched)", overlay=true)
//────────────────────────────────────
// TREND TABLE SETTINGS
//────────────────────────────────────
groupTrend = "Trend Table"
showTrendTable = input.bool(true, "Show Trend Table", group=groupTrend)
trendTablePositionInput = input.string(
"Middle Right",
"Table Position",
options=[
"Top Left","Top Center","Top Right",
"Middle Left","Middle Center","Middle Right",
"Bottom Left","Bottom Center","Bottom Right"
],
group=groupTrend)
trendTextSize = input.string(
"Small",
"Text Size",
options=["Tiny","Small","Normal","Large"],
group=groupTrend)
strongBullColor = input.color(color.rgb(0,120,60), "Strong Bullish", group=groupTrend)
bullColor = input.color(color.rgb(0,90,45), "Bullish", group=groupTrend)
earlyBullColor = input.color(color.rgb(90,100,20), "Early Bullish", group=groupTrend)
neutralColor = input.color(color.rgb(55,55,55), "Neutral", group=groupTrend)
earlyBearColor = input.color(color.rgb(110,70,20), "Early Bearish", group=groupTrend)
bearColor = input.color(color.rgb(100,25,25), "Bearish", group=groupTrend)
strongBearColor = input.color(color.rgb(140,0,0), "Strong Bearish", group=groupTrend)
textColor = input.color(color.white, "Text Color", group=groupTrend)
//────────────────────────────────────
// TABLE POSITION
//────────────────────────────────────
f_getPosition() =>
switch trendTablePositionInput
"Top Left" => position.top_left
"Top Center" => position.top_center
"Top Right" => position.top_right
"Middle Left" => position.middle_left
"Middle Center" => position.middle_center
"Middle Right" => position.middle_right
"Bottom Left" => position.bottom_left
"Bottom Center" => position.bottom_center
"Bottom Right" => position.bottom_right
//────────────────────────────────────
// TEXT SIZE
//────────────────────────────────────
f_textSize() =>
switch trendTextSize
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
//────────────────────────────────────
// LOCAL CALCULATION FUNCTION FOR MTF
// Evaluated on the target timeframe directly
//────────────────────────────────────
f_calcScoreLocal() =>
c = close
e20 = ta.ema(close, 20)
e50 = ta.ema(close, 50)
e20Prev = e20[5]
e50Prev = e50[5]
cPrev5 = close[5]
h20 = ta.highest(high, 20)[1]
l20 = ta.lowest(low, 20)[1]
ph0 = ta.valuewhen(not na(ta.pivothigh(high, 3, 3)), ta.pivothigh(high, 3, 3), 0)
ph1 = ta.valuewhen(not na(ta.pivothigh(high, 3, 3)), ta.pivothigh(high, 3, 3), 1)
pl0 = ta.valuewhen(not na(ta.pivotlow(low, 3, 3)), ta.pivotlow(low, 3, 3), 0)
pl1 = ta.valuewhen(not na(ta.pivotlow(low, 3, 3)), ta.pivotlow(low, 3, 3), 1)
s = 0
// Price vs 20 EMA
if c > e20
s += 1
else if c < e20
s -= 1
// Price vs 50 EMA
if c > e50
s += 1
else if c < e50
s -= 1
// 20 EMA direction
if e20 > e20Prev
s += 1
else if e20 < e20Prev
s -= 1
// 50 EMA direction
if e50 > e50Prev
s += 1
else if e50 < e50Prev
s -= 1
// Momentum
if c > cPrev5
s += 1
else if c < cPrev5
s -= 1
// Market structure
bool bullStruct = not na(ph0) and not na(ph1) and not na(pl0) and not na(pl1) and ph0 > ph1 and pl0 > pl1
bool bearStruct = not na(ph0) and not na(ph1) and not na(pl0) and not na(pl1) and ph0 < ph1 and pl0 < pl1
if bullStruct
s += 2
else if bearStruct
s -= 2
// 20-bar breakout / breakdown
if c > h20
s += 1
else if c < l20
s -= 1
s
//────────────────────────────────────
// NON-REPAINTING MTF TREND SCORE WRAPPER
// Uses closed bar [1] if target timeframe is higher than chart timeframe
//────────────────────────────────────
f_getTrend(string tf) =>
request.security(syminfo.tickerid, tf, f_calcScoreLocal()[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
//────────────────────────────────────
// MULTI-TIMEFRAME SCORES
//────────────────────────────────────
trend1m = f_getTrend("1")
trend3m = f_getTrend("3")
trend5m = f_getTrend("5")
trend15m = f_getTrend("15")
trend30m = f_getTrend("30")
trend1H = f_getTrend("60")
trend4H = f_getTrend("240")
trend1D = f_getTrend("D")
trend1W = f_getTrend("W")
//────────────────────────────────────
// TREND STATE & SYMBOLS
//────────────────────────────────────
f_trendState(int score) =>
score >= 7 ? "STRONG BULL" :
score >= 4 ? "BULLISH" :
score >= 2 ? "EARLY BULL" :
score <= -7 ? "STRONG BEAR" :
score <= -4 ? "BEARISH" :
score <= -2 ? "EARLY BEAR" :
"NEUTRAL"
f_trendSymbol(int score) =>
score >= 7 ? "▲▲" :
score >= 4 ? "▲" :
score >= 2 ? "↗" :
score <= -7 ? "▼▼" :
score <= -4 ? "▼" :
score <= -2 ? "↘" :
"●"
f_trendColor(int score) =>
score >= 7 ? strongBullColor :
score >= 4 ? bullColor :
score >= 2 ? earlyBullColor :
score <= -7 ? strongBearColor :
score <= -4 ? bearColor :
score <= -2 ? earlyBearColor :
neutralColor
//────────────────────────────────────
// INTRADAY BIAS
//────────────────────────────────────
int intradayBias = 0
if trend1H >= 4 and trend15m >= 2 and trend5m >= 2
intradayBias := 1
else if trend1H <= -4 and trend15m <= -2 and trend5m <= -2
intradayBias := -1
intradayScore = trend5m + trend15m + trend1H
//────────────────────────────────────
// SWING BIAS
//────────────────────────────────────
int swingBias = 0
if trend1W >= 2 and trend1D >= 2 and trend4H >= 0
swingBias := 1
else if trend1W <= -2 and trend1D <= -2 and trend4H <= 0
swingBias := -1
swingScore = trend4H + trend1D + trend1W
//────────────────────────────────────
// 5-MINUTE ENTRY ENGINE (Confirmed 5m Closes)
//────────────────────────────────────
[
entryClose,
entryLow,
entryHigh,
entryEMAHigh,
entryEMALow
] = request.security(
syminfo.tickerid,
"5",
[
close[1],
low[1],
high[1],
ta.ema(high, 34)[1],
ta.ema(low, 34)[1]
],
gaps=barmerge.gaps_off,
lookahead=barmerge.lookahead_off)
longReclaim = entryLow <= entryEMAHigh and entryClose > entryEMAHigh
shortReclaim = entryHigh >= entryEMALow and entryClose < entryEMALow
bool longEntry = intradayBias == 1 and longReclaim
bool shortEntry = intradayBias == -1 and shortReclaim
string entrySignal = longEntry ? "LONG ENTRY" : shortEntry ? "SHORT ENTRY" : "WAIT"
color entrySignalColor = longEntry ? bullColor : shortEntry ? bearColor : neutralColor
//────────────────────────────────────
// SCALPING ENTRY ENGINE (Confirmed 3m Closes)
//────────────────────────────────────
[
scalpClose,
scalpHigh,
scalpLow,
scalpEMA34High,
scalpEMA34Low,
scalpEMA20,
scalpEMA20Prev2,
scalpClosePrev2
] = request.security(
syminfo.tickerid,
"3",
[
close[1],
high[1],
low[1],
ta.ema(high, 34)[1],
ta.ema(low, 34)[1],
ta.ema(close, 20)[1],
ta.ema(close, 20)[3],
close[3]
],
gaps=barmerge.gaps_off,
lookahead=barmerge.lookahead_off)
bool scalpBullDirection = trend15m >= 2 and trend5m >= 2 and trend3m >= 2
bool scalpBearDirection = trend15m <= -2 and trend5m <= -2 and trend3m <= -2
bool scalpBullMomentum = scalpClose > scalpClosePrev2 and scalpEMA20 > scalpEMA20Prev2
bool scalpBearMomentum = scalpClose < scalpClosePrev2 and scalpEMA20 < scalpEMA20Prev2
bool scalpLongReclaim = scalpLow <= scalpEMA34High and scalpClose > scalpEMA34High
bool scalpShortReclaim = scalpHigh >= scalpEMA34Low and scalpClose < scalpEMA34Low
bool scalpLongEntry = scalpBullDirection and scalpBullMomentum and scalpLongReclaim
bool scalpShortEntry = scalpBearDirection and scalpBearMomentum and scalpShortReclaim
string scalpSignal = scalpLongEntry ? "SCALP LONG" : scalpShortEntry ? "SCALP SHORT" : "WAIT"
color scalpSignalColor = scalpLongEntry ? bullColor : scalpShortEntry ? bearColor : neutralColor
//────────────────────────────────────
// DASHBOARD METRICS & SYNCHRONIZED BIAS
//────────────────────────────────────
rsiValue = ta.rsi(close, 14)
[macdLine, macdSignalLine, _] = ta.macd(close, 12, 26, 9)
stochK = ta.stoch(close, high, low, 14)
stochD = ta.sma(stochK, 3)
volSma20 = ta.sma(volume, 20)
volRatio = not na(volSma20) and volSma20 > 0 ? volume / volSma20 : na
ema20Dashboard = ta.ema(close, 20)
trendStrengthPct = ema20Dashboard != 0 ? math.abs(close - ema20Dashboard) / ema20Dashboard * 100 : na
// Patched: Synchronised with intradayBias engine
string trendBiasText = intradayBias == 1 ? "BULLISH" : intradayBias == -1 ? "BEARISH" : "NEUTRAL"
color trendBiasColor = intradayBias == 1 ? color.rgb(0,190,150) : intradayBias == -1 ? color.rgb(220,65,85) : color.rgb(190,150,70)
string trendStrengthText = na(trendStrengthPct) ? "N/A" : (trendStrengthPct >= 1.5 ? "STRONG" : trendStrengthPct >= 0.5 ? "MODERATE" : "WEAK") + " (" + str.tostring(trendStrengthPct, "#.##") + "%)"
color trendStrengthColor = na(trendStrengthPct) ? color.gray : trendStrengthPct >= 1.5 ? color.rgb(0,190,150) : trendStrengthPct >= 0.5 ? color.rgb(210,155,45) : color.rgb(220,160,60)
string volumeStrengthText = na(volRatio) ? "N/A" : volRatio >= 1.5 ? "HIGH" : volRatio >= 0.8 ? "NORMAL" : "LOW"
color volumeStrengthColor = na(volRatio) ? color.gray : volRatio >= 1.5 ? color.rgb(0,190,150) : volRatio >= 0.8 ? color.rgb(210,155,45) : color.rgb(220,80,110)
string rsiText = str.tostring(rsiValue, "#.##")
color rsiColor = rsiValue >= 60 ? color.rgb(0,190,150) : rsiValue <= 40 ? color.rgb(220,65,85) : color.rgb(220,165,60)
string macdText = macdLine > macdSignalLine ? "BULLISH" : macdLine < macdSignalLine ? "BEARISH" : "NEUTRAL"
color macdColor = macdLine > macdSignalLine ? color.rgb(0,190,150) : macdLine < macdSignalLine ? color.rgb(220,65,85) : color.rgb(190,150,70)
string stochText = stochK > stochD and stochK < 80 ? "BULLISH" : stochK < stochD and stochK > 20 ? "BEARISH" : stochK >= 80 ? "OVERBOUGHT" : stochK <= 20 ? "OVERSOLD" : "NEUTRAL"
color stochColor = stochK > stochD and stochK < 80 ? color.rgb(0,190,150) : stochK < stochD and stochK > 20 ? color.rgb(220,65,85) : color.rgb(210,155,45)
f_tfText(int score) => f_trendSymbol(score) + " " + f_trendState(score)
f_tfColor(int score) => f_trendColor(score)
//────────────────────────────────────
// DASHBOARD RENDERING
//────────────────────────────────────
var table trendTable = table.new(
f_getPosition(), 2, 17,
bgcolor=color.rgb(12,16,27),
frame_color=color.rgb(65,75,92), frame_width=1,
border_color=color.new(color.rgb(90,100,120),65), border_width=1)
f_dashboardRow(int row, string label, string value, color valueColor) =>
table.cell(trendTable, 0, row, label, text_color=color.rgb(225,230,240), text_size=f_textSize(), bgcolor=color.rgb(20,27,41), text_halign=text.align_left)
table.cell(trendTable, 1, row, value, text_color=valueColor, text_size=f_textSize(), bgcolor=color.rgb(15,21,34), text_halign=text.align_right)
if barstate.islast and showTrendTable
table.cell(trendTable, 0, 0, "TREND DASHBOARD", text_color=color.white, text_size=f_textSize(), bgcolor=color.rgb(32,43,61), text_halign=text.align_left)
table.cell(trendTable, 1, 0, syminfo.ticker, text_color=color.white, text_size=f_textSize(), bgcolor=color.rgb(32,43,61), text_halign=text.align_right)
f_dashboardRow(1, "Trend Bias", trendBiasText, trendBiasColor)
f_dashboardRow(2, "Trend Strength", trendStrengthText, trendStrengthColor)
f_dashboardRow(3, "Volume Strength", volumeStrengthText, volumeStrengthColor)
f_dashboardRow(4, "RSI (14)", rsiText, rsiColor)
f_dashboardRow(5, "MACD Signal", macdText, macdColor)
f_dashboardRow(6, "Stoch Momentum", stochText, stochColor)
table.cell(trendTable, 0, 7, "TIMEFRAME ANALYSIS", text_color=color.white, text_size=f_textSize(), bgcolor=color.rgb(32,43,61), text_halign=text.align_center)
table.cell(trendTable, 1, 7, "BIAS", text_color=color.white, text_size=f_textSize(), bgcolor=color.rgb(32,43,61), text_halign=text.align_center)
f_dashboardRow(8, "1 Min", f_tfText(trend1m), f_tfColor(trend1m))
f_dashboardRow(9, "3 Min", f_tfText(trend3m), f_tfColor(trend3m))
f_dashboardRow(10, "5 Min", f_tfText(trend5m), f_tfColor(trend5m))
f_dashboardRow(11, "15 Min", f_tfText(trend15m), f_tfColor(trend15m))
f_dashboardRow(12, "30 Min", f_tfText(trend30m), f_tfColor(trend30m))
f_dashboardRow(13, "1 Hour", f_tfText(trend1H), f_tfColor(trend1H))
f_dashboardRow(14, "4 Hour", f_tfText(trend4H), f_tfColor(trend4H))
f_dashboardRow(15, "Daily", f_tfText(trend1D), f_tfColor(trend1D))
f_dashboardRow(16, "Weekly", f_tfText(trend1W), f_tfColor(trend1W))
if barstate.islast and not showTrendTable
table.clear(trendTable, 0, 0, 1, 16)
//────────────────────────────────────
// 34 EMA CHANNEL (Plotted on Current Chart)
//────────────────────────────────────
groupEMA34 = "34 EMA Channel"
showEMA34High = input.bool(true, "Show 34 EMA High", group=groupEMA34)
showEMA34Low = input.bool(true, "Show 34 EMA Low", group=groupEMA34)
ema34HighColor = input.color(color.orange, "34 EMA High Color", group=groupEMA34)
ema34LowColor = input.color(color.aqua, "34 EMA Low Color", group=groupEMA34)
ema34Width = input.int(2, "Line Width", minval=1, maxval=5, group=groupEMA34)
ema34High = ta.ema(high, 34)
ema34Low = ta.ema(low, 34)
plot(showEMA34High ? ema34High : na, title="34 EMA High", color=ema34HighColor, linewidth=ema34Width)
plot(showEMA34Low ? ema34Low : na, title="34 EMA Low", color=ema34LowColor, linewidth=ema34Width)
//────────────────────────────────────
//────────────────────────────────────
// SIMPLE MOVING AVERAGES (Current Chart)
//────────────────────────────────────
groupSMA = "Simple Moving Averages (SMA)"
showSMA10 = input.bool(true, "Show 10 SMA", group=groupSMA)
showSMA50 = input.bool(true, "Show 50 SMA", group=groupSMA)
showSMA200 = input.bool(true, "Show 200 SMA", group=groupSMA)
sma10Color = input.color(color.yellow, "10 SMA Color", group=groupSMA)
sma50Color = input.color(color.blue, "50 SMA Color", group=groupSMA)
sma200Color = input.color(color.fuchsia, "200 SMA Color", group=groupSMA)
smaWidth = input.int(2, "SMA Line Width", minval=1, maxval=5, group=groupSMA)
sma10 = ta.sma(close, 10)
sma50 = ta.sma(close, 50)
sma200 = ta.sma(close, 200)
plot(showSMA10 ? sma10 : na, title="10 SMA", color=sma10Color, linewidth=smaWidth)
plot(showSMA50 ? sma50 : na, title="50 SMA", color=sma50Color, linewidth=smaWidth)
plot(showSMA200 ? sma200 : na, title="200 SMA", color=sma200Color, linewidth=smaWidth)
// ALERTS
//────────────────────────────────────
crossAboveEMA34High = ta.crossover(close, ema34High)
crossBelowEMA34Low = ta.crossunder(close, ema34Low)
alertcondition(crossAboveEMA34High, title="Price Crossed Above 34 EMA High", message="{{ticker}} price crossed ABOVE the 34 EMA High on {{interval}}.")
alertcondition(crossBelowEMA34Low, title="Price Crossed Below 34 EMA Low", message="{{ticker}} price crossed BELOW the 34 EMA Low on {{interval}}.")
alertcondition(longEntry, title="Intraday Long Entry", message="{{ticker}} LONG ENTRY: Intraday bias bullish + 5m 34 EMA High reclaim.")
alertcondition(shortEntry, title="Intraday Short Entry", message="{{ticker}} SHORT ENTRY: Intraday bias bearish + 5m 34 EMA Low reclaim.")
alertcondition(scalpLongEntry, title="Scalp Long Entry", message="{{ticker}} SCALP LONG: 15m + 5m + 3m bullish with 3m 34 EMA High reclaim.")
alertcondition(scalpShortEntry, title="Scalp Short Entry", message="{{ticker}} SCALP SHORT: 15m + 5m + 3m bearish with 3m 34 EMA Low reclaim.")
//────────────────────────────────────
// PINE SCREENER OUTPUTS
//────────────────────────────────────
plot(intradayBias, title="Intraday Bias", display=display.data_window)
plot(swingBias, title="Swing Bias", display=display.data_window)
plot(intradayScore, title="Intraday Score", display=display.data_window)
plot(swingScore, title="Swing Score", display=display.data_window)
plot(trend5m, title="5m Trend Score", display=display.data_window)
plot(trend15m, title="15m Trend Score", display=display.data_window)
plot(trend1H, title="1H Trend Score", display=display.data_window)
plot(trend4H, title="4H Trend Score", display=display.data_window)
plot(trend1D, title="1D Trend Score", display=display.data_window)
plot(trend1W, title="1W Trend Score", display=display.data_window)