本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Therlastr Fixed TP Dashboard", overlay=true)
// ───── SETTINGS ─────
mode = input.string("NONE", "Trade Mode", options=["NONE", "LONG", "SHORT"])
entry = input.float(4000.0, "Entry Price", step=0.1)
sl = input.float(3990.0, "Stop Loss", step=0.1)
tpStep = input.float(2.0, "Fixed TP Distance", minval=0.1, step=0.1)
dashSize = input.string("Normal", "Dashboard Size", options=["Small", "Normal", "Large"])
transparency = input.int(15, "Color Transparency", minval=0, maxval=100)
showLines = input.bool(true, "Show Price Lines")
// ───── CALCULATIONS ─────
active = mode != "NONE"
isLong = mode == "LONG"
dir = isLong ? 1.0 : -1.0
tp1 = entry + dir * tpStep
tp2 = entry + dir * tpStep * 2
tp3 = entry + dir * tpStep * 3
tp4 = entry + dir * tpStep * 4
tp5 = entry + dir * tpStep * 5
risk = math.abs(entry - sl)
rr1 = risk > 0 ? math.abs(tp1 - entry) / risk : na
rr2 = risk > 0 ? math.abs(tp2 - entry) / risk : na
rr3 = risk > 0 ? math.abs(tp3 - entry) / risk : na
rr4 = risk > 0 ? math.abs(tp4 - entry) / risk : na
rr5 = risk > 0 ? math.abs(tp5 - entry) / risk : na
// ───── COLORS ─────
panelColor = mode == "LONG" ? color.new(color.green, transparency) :
mode == "SHORT" ? color.new(color.gray, transparency) :
color.new(color.gray, 75)
headerColor = color.new(color.black, 65)
entryColor = color.new(color.blue, transparency)
slColor = color.new(color.red, transparency)
tpColor = color.new(color.green, transparency)
modeColor = mode == "SHORT" ? color.red :
mode == "LONG" ? color.green : color.gray
txtSize = dashSize == "Small" ? size.tiny :
dashSize == "Large" ? size.normal : size.small
fmt(x) => str.tostring(x, format.mintick)
rrFmt(x) => na(x) ? "—" : "1:" + str.tostring(x, "#.##")
// ───── CHART LEVELS ─────
plot(active and showLines ? sl : na, "STOP LOSS", color=color.red, linewidth=2)
plot(active and showLines ? entry : na, "ENTRY", color=color.blue, linewidth=2)
plot(active and showLines ? tp1 : na, "TP1", color=color.lime)
plot(active and showLines ? tp2 : na, "TP2", color=color.lime)
plot(active and showLines ? tp3 : na, "TP3", color=color.lime)
plot(active and showLines ? tp4 : na, "TP4", color=color.lime)
plot(active and showLines ? tp5 : na, "TP5", color=color.lime)
// ───── DASHBOARD ─────
var table dash = table.new(position.top_right, 3, 10, border_width=1,
frame_color=color.new(color.gray, 70))
if barstate.islast
table.clear(dash, 0, 0, 2, 9)
// Header
table.cell(dash, 0, 0, "THERLASTR", bgcolor=headerColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 1, 0, "FIXED TP", bgcolor=headerColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 2, 0, mode, bgcolor=modeColor,
text_color=color.white, text_size=txtSize)
if active
// Stop loss first
table.cell(dash, 0, 1, "STOP LOSS", bgcolor=slColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 1, 1, fmt(sl), bgcolor=slColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 2, 1, "RISK " + fmt(risk), bgcolor=slColor,
text_color=color.white, text_size=txtSize)
// Entry second
table.cell(dash, 0, 2, "ENTRY", bgcolor=entryColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 1, 2, fmt(entry), bgcolor=entryColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 2, 2, "—", bgcolor=entryColor,
text_color=color.white, text_size=txtSize)
// Targets always green, even in SHORT mode
table.cell(dash, 0, 3, "TP1", bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 1, 3, fmt(tp1), bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 2, 3, rrFmt(rr1), bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 0, 4, "TP2", bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 1, 4, fmt(tp2), bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 2, 4, rrFmt(rr2), bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 0, 5, "TP3", bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 1, 5, fmt(tp3), bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 2, 5, rrFmt(rr3), bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 0, 6, "TP4", bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 1, 6, fmt(tp4), bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 2, 6, rrFmt(rr4), bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 0, 7, "TP5", bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 1, 7, fmt(tp5), bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 2, 7, rrFmt(rr5), bgcolor=tpColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 0, 8, "TP DISTANCE", bgcolor=panelColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 1, 8, str.tostring(tpStep) + " USD", bgcolor=panelColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 2, 8, "FIXED", bgcolor=panelColor,
text_color=color.white, text_size=txtSize)
table.cell(dash, 0, 9, "MOVE STOP-LOSS", bgcolor=panelColor,
text_color=color.black, text_size=txtSize)
table.cell(dash, 1, 9, "TO BREAKEVEN", bgcolor=panelColor,
text_color=color.black, text_size=txtSize)
table.cell(dash, 2, 9, "BE", bgcolor=panelColor,
text_color=color.black, text_size=txtSize)