本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// Trend Desk [Badr Edge] · v1.0.0
// Educational chart-marking tool. Markers show what happened on a bar. They are not trade signals.
indicator("Trend Desk [Badr Edge]", shorttitle = "BE Trend", overlay = true)
const color GOLD = #D9B46C
const color TEAL = #4FB8A0
const color ROSE = #E07A6C
const color GREY = #8F939B
const color PANEL = #0F1013
const string G_C = "Checks"
useDaily = input.bool(true, "Daily trend", inline = "d", group = G_C, tooltip = "Fast daily EMA above or below the slow daily EMA, from completed days only.")
dFast = input.int(20, "", minval = 2, inline = "d", group = G_C)
dSlow = input.int(50, "", minval = 5, inline = "d", group = G_C)
useEma = input.bool(true, "Price vs EMA", inline = "e", group = G_C)
emaLen = input.int(200, "", minval = 10, inline = "e", group = G_C)
useVwap = input.bool(true, "Price vs session VWAP", group = G_C)
useSar = input.bool(true, "Parabolic SAR side", group = G_C)
useVol = input.bool(false, "Volume above its 20-bar average", group = G_C, tooltip = "Optional. When on, an alignment marker also needs above-average volume on that bar.")
const string G_V = "Visuals"
showEma = input.bool(true, "EMA line", group = G_V)
showVwap = input.bool(true, "VWAP line", group = G_V)
showSar = input.bool(false, "SAR dots", group = G_V)
showTable = input.bool(true, "Checklist table", group = G_V)
tablePos = input.string("Top right", "Table position", options = ["Top right", "Top left", "Bottom left"], group = G_V)
showMarks = input.bool(true, "Alignment markers", group = G_V, tooltip = "A small triangle on the bar where every enabled check first points the same way. A marker shows what happened. It is not a trade signal.")
coolBars = input.int(40, "Bars between markers", minval = 0, maxval = 500, group = G_V)
const string G_Y = "Style"
showWm = input.bool(true, "Watermark", group = G_Y)
const string G_A = "Alerts"
useAlerts = input.bool(true, "Alert when all checks align", group = G_A, tooltip = "Create the alert with \"Any alert() function call\". Fires once, after the bar closes.")
ema = ta.ema(close, emaLen)
vw = ta.vwap(hlc3)
sar = ta.sar(0.02, 0.02, 0.2)
[dF, dS] = request.security(syminfo.tickerid, "D", [ta.ema(close, dFast)[1], ta.ema(close, dSlow)[1]], lookahead = barmerge.lookahead_on)
hasVwap = timeframe.isintraday and not na(vw)
int sDaily = na(dF) or na(dS) ? 0 : dF > dS ? 1 : -1
int sEma = na(ema) ? 0 : close > ema ? 1 : -1
int sVwap = not hasVwap ? 0 : close > vw ? 1 : -1
int sSar = na(sar) ? 0 : close > sar ? 1 : -1
volAvg = ta.sma(volume, 20)
bool volOK = not useVol or volume > volAvg
int used = (useDaily ? 1 : 0) + (useEma ? 1 : 0) + (useVwap ? 1 : 0) + (useSar ? 1 : 0)
int sum = (useDaily ? sDaily : 0) + (useEma ? sEma : 0) + (useVwap ? sVwap : 0) + (useSar ? sSar : 0)
bool allUp = used > 0 and sum == used
bool allDn = used > 0 and sum == -used
var int lastUp = na
var int lastDn = na
bool up = false
bool dn = false
if barstate.isconfirmed
up := allUp and not allUp[1] and volOK and (na(lastUp) or bar_index - lastUp >= coolBars)
dn := allDn and not allDn[1] and volOK and (na(lastDn) or bar_index - lastDn >= coolBars)
if up
lastUp := bar_index
if dn
lastDn := bar_index
plot(showEma ? ema : na, "EMA", color.new(GOLD, 15), 1)
plot(showVwap and hasVwap ? vw : na, "Session VWAP", color.new(TEAL, 30), 1, plot.style_linebr)
plot(showSar ? sar : na, "Parabolic SAR", color.new(GREY, 45), 1, plot.style_circles)
plotshape(showMarks and up, "All checks point up", shape.triangleup, location.belowbar, color.new(TEAL, 0), size = size.tiny)
plotshape(showMarks and dn, "All checks point down", shape.triangledown, location.abovebar, color.new(ROSE, 0), size = size.tiny)
plot(sum, "Checks pointing up minus down", display = display.data_window)
if useAlerts and up
alert(syminfo.ticker + ": all enabled trend checks point up", alert.freq_once_per_bar_close)
if useAlerts and dn
alert(syminfo.ticker + ": all enabled trend checks point down", alert.freq_once_per_bar_close)
row(table t, int r, string name, int s, bool on) =>
if on
t.cell(0, r, name, text_color = color.new(GREY, 0), text_size = size.small, text_halign = text.align_left, bgcolor = color.new(PANEL, 10))
t.cell(1, r, s == 1 ? "▲" : s == -1 ? "▼" : "·", text_color = s == 1 ? TEAL : s == -1 ? ROSE : GREY, text_size = size.small, bgcolor = color.new(PANEL, 10))
var table desk = table.new(tablePos == "Top right" ? position.top_right : tablePos == "Top left" ? position.top_left : position.bottom_left, 2, 6, border_width = 0, frame_color = color.new(GREY, 75), frame_width = 1)
if barstate.islast and showTable
desk.cell(0, 0, "TREND DESK", text_color = GOLD, text_size = size.small, text_halign = text.align_left, bgcolor = color.new(PANEL, 10))
desk.cell(1, 0, str.tostring(math.abs(sum)) + "/" + str.tostring(used), text_color = allUp ? TEAL : allDn ? ROSE : GREY, text_size = size.small, bgcolor = color.new(PANEL, 10))
row(desk, 1, "Daily trend", sDaily, useDaily)
row(desk, 2, "EMA " + str.tostring(emaLen), sEma, useEma)
row(desk, 3, "Session VWAP", sVwap, useVwap)
row(desk, 4, "Parabolic SAR", sSar, useSar)
var table wm = table.new(position.bottom_right, 1, 1)
if barstate.islast and showWm
wm.cell(0, 0, "BADR EDGE", text_color = color.new(GREY, 72), text_size = size.small)