P/L Panel + Multi Targets (4 Entries) – HUD near Price + Avg R:R//@version=6
indicator("P/L Panel + Multi Targets (4 Entries) – HUD near Price + Avg R:R", overlay=true, max_lines_count=500, max_labels_count=500)
// ====== General =====
side = input.string("Long", "Position Side", options= )
usd_dp = input.int(2, "USD decimals", minval=0, maxval=6)
// ====== HUD Settings ======
hud_font = input.string("large", "HUD font size", options= )
hud_bg = input.color(color.new(color.black, 0), "HUD background color")
hud_txtc = input.color(color.white, "HUD text color")
hud_side = input.string("Right of price", "HUD side", options= )
hud_off_bars = input.int(3, "Horizontal offset (bars)", minval=0, maxval=50)
hud_off_atr = input.float(0.2, "Vertical offset from price (ATR)", step=0.1)
atr_len = input.int(14, "ATR length for vertical offset", minval=1)
lock_to_last_bar = input.bool(true, "Lock HUD to the last bar")
// Show HUD even when there are no entries (test text)
force_show_hud = input.bool(true, "🔍 Show HUD even with no entries")
// ====== Shared SL & Targets ======
stop_inp = input.float(0.0, "Stop Loss (shared, optional)", step=0.0001)
use_tp1 = input.bool(false, "Enable Target 1")
tp1 = input.float(0.0, "Target 1 price", step=0.0001)
use_tp2 = input.bool(false, "Enable Target 2")
tp2 = input.float(0.0, "Target 2 price", step=0.0001)
use_tp3 = input.bool(false, "Enable Target 3")
tp3 = input.float(0.0, "Target 3 price", step=0.0001)
use_tp4 = input.bool(false, "Enable Target 4")
tp4 = input.float(0.0, "Target 4 price", step=0.0001)
use_tp5 = input.bool(false, "Enable Target 5")
tp5 = input.float(0.0, "Target 5 price", step=0.0001)
// ====== Four Independent Entries ======
group1 = "Entry 1"
en1 = input.bool(true, "Enable Entry 1", inline=group1)
lev1 = input.int(10, "Leverage", minval=1, maxval=200, inline=group1)
entry1 = input.float(0.0, "Entry 1 price", step=0.0001)
set_now1 = input.bool(false, "⚡ Set Entry1 = Current Price")
mode1 = input.string("USD (USDT)", "Size unit 1", options= )
sem1 = input.string("Margin (apply leverage)", "Size meaning 1", options= )
size1 = input.float(0.0, "Position size 1", step=0.0001)
baseLev1 = input.bool(false, "Apply leverage to 'Coin Quantity' (1)")
group2 = "Entry 2"
en2 = input.bool(false, "Enable Entry 2", inline=group2)
lev2 = input.int(10, "Leverage", minval=1, maxval=200, inline=group2)
entry2 = input.float(0.0, "Entry 2 price", step=0.0001)
set_now2 = input.bool(false, "⚡ Set Entry2 = Current Price")
mode2 = input.string("USD (USDT)", "Size unit 2", options= )
sem2 = input.string("Margin (apply leverage)", "Size meaning 2", options= )
size2 = input.float(0.0, "Position size 2", step=0.0001)
baseLev2 = input.bool(false, "Apply leverage to 'Coin Quantity' (2)")
group3 = "Entry 3"
en3 = input.bool(false, "Enable Entry 3", inline=group3)
lev3 = input.int(10, "Leverage", minval=1, maxval=200, inline=group3)
entry3 = input.float(0.0, "Entry 3 price", step=0.0001)
set_now3 = input.bool(false, "⚡ Set Entry3 = Current Price")
mode3 = input.string("USD (USDT)", "Size unit 3", options= )
sem3 = input.string("Margin (apply leverage)", "Size meaning 3", options= )
size3 = input.float(0.0, "Position size 3", step=0.0001)
baseLev3 = input.bool(false, "Apply leverage to 'Coin Quantity' (3)")
group4 = "Entry 4"
en4 = input.bool(false, "Enable Entry 4", inline=group4)
lev4 = input.int(10, "Leverage", minval=1, maxval=200, inline=group4)
entry4 = input.float(0.0, "Entry 4 price", step=0.0001)
set_now4 = input.bool(false, "⚡ Set Entry4 = Current Price")
mode4 = input.string("USD (USDT)", "Size unit 4", options= )
sem4 = input.string("Margin (apply leverage)", "Size meaning 4", options= )
size4 = input.float(0.0, "Position size 4", step=0.0001)
baseLev4 = input.bool(false, "Apply leverage to 'Coin Quantity' (4)")
// Quick set entries = current price
entry1 := (en1 and set_now1) ? close : entry1
entry2 := (en2 and set_now2) ? close : entry2
entry3 := (en3 and set_now3) ? close : entry3
entry4 := (en4 and set_now4) ? close : entry4
// ====== Helpers ======
to_size(s) =>
s == "tiny" ? size.tiny : s == "small" ? size.small : s == "normal" ? size.normal : s == "large" ? size.large : size.huge
f_usd_str(_val, _decimals) =>
na(_val) ? "—" : str.tostring(math.round(_val * math.pow(10, _decimals)) / math.pow(10, _decimals))
f_qty_base(mode, sem, size, entry, baseLev, lev) =>
float _qty = na
if mode == "USD (USDT)"
_qty := (size > 0 and entry > 0) ? ((sem == "Margin (apply leverage)" ? size * lev : size) / entry) : na
else
_qty := size > 0 ? (baseLev ? size * lev : size) : na
_qty
f_notional_quote(mode, sem, size, entry, lev, baseLev) =>
if mode == "USD (USDT)"
sem == "Margin (apply leverage)" ? size * lev : size
else
(baseLev ? size * lev : size) * entry
f_pnl_quote(side, entry, qty) =>
na(qty) or na(entry) ? na : (side=="Long" ? (close - entry) : (entry - close)) * qty
f_pct(side, entry) =>
na(entry) ? na : ((close - entry) / entry * 100.0) * (side=="Long" ? 1 : -1)
f_roi_pct(side, entry, lev) =>
na(entry) ? na : f_pct(side, entry) * lev
// NOTE: _lineIn must be a line, not a float
f_stickyHLine(_price, _lineIn, _color, _width) =>
var line _out = na
_out := _lineIn
if na(_out)
_out := line.new(bar_index-1, _price, bar_index+1, _price, xloc=xloc.bar_index, extend=extend.both, width=_width, style=line.style_dashed, color=_color)
else
line.set_xy1(_out, bar_index-1, _price)
line.set_xy2(_out, bar_index+1, _price)
line.set_color(_out, _color)
line.set_width(_out, _width)
_out
// ====== 4 Entries Calculations ======
var color entryCols = array.from(color.new(color.yellow, 0), color.new(color.orange, 0), color.new(color.teal, 0), color.new(color.fuchsia, 0))
bool ens = array.from(en1, en2, en3, en4)
float entries = array.from(entry1, entry2, entry3, entry4)
int levs = array.from(lev1, lev2, lev3, lev4)
string modes = array.from(mode1, mode2, mode3, mode4)
string sems = array.from(sem1, sem2, sem3, sem4)
float sizes = array.from(size1, size2, size3, size4)
bool baseLevs = array.from(baseLev1, baseLev2, baseLev3, baseLev4)
float qtys = array.new_float(4, na)
float pnls = array.new_float(4, na)
float pcts = array.new_float(4, na)
float rois = array.new_float(4, na)
float notionals = array.new_float(4, na)
for i = 0 to 3
if array.get(ens, i) and array.get(entries, i) > 0
ent = array.get(entries, i)
levX = array.get(levs, i)
modeX= array.get(modes, i)
semX = array.get(sems, i)
sizeX= array.get(sizes, i)
bLev = array.get(baseLevs, i)
qty = f_qty_base(modeX, semX, sizeX, ent, bLev, levX)
array.set(qtys, i, qty)
pnlq = f_pnl_quote(side, ent, qty)
array.set(pnls, i, pnlq)
pct = f_pct(side, ent)
array.set(pcts, i, pct)
roi = f_roi_pct(side, ent, levX)
array.set(rois, i, roi)
notq = f_notional_quote(modeX, semX, sizeX, ent, levX, bLev)
array.set(notionals, i, notq)
// ====== Totals & Weighted Avg Entry ======
float totalPnlUSD = 0.0
float totalNotional = 0.0
float totalQty = 0.0
float wAvgEntry = na
for i = 0 to 3
if not na(array.get(pnls, i))
totalPnlUSD += array.get(pnls, i)
if not na(array.get(notionals, i))
totalNotional += array.get(notionals, i)
if not na(array.get(qtys, i)) and array.get(entries, i) > 0
totalQty += array.get(qtys, i)
if totalQty > 0
num = 0.0
for i = 0 to 3
qi = array.get(qtys, i)
ei = array.get(entries, i)
if not na(qi) and ei > 0
num += qi * ei
wAvgEntry := num / totalQty
totalROIweighted = totalNotional > 0 ? (totalPnlUSD / totalNotional) * 100.0 : na
// ====== Nearest TP & R:R ======
float nearestTP = na
float nearestDistPrice = na
float nearestDistPct = na
float risk_pct = na
float reward_pct = na
float rr = na
var float tps = array.new_float()
array.clear(tps)
if use_tp1 and tp1 > 0
array.push(tps, tp1)
if use_tp2 and tp2 > 0
array.push(tps, tp2)
if use_tp3 and tp3 > 0
array.push(tps, tp3)
if use_tp4 and tp4 > 0
array.push(tps, tp4)
if use_tp5 and tp5 > 0
array.push(tps, tp5)
// nearest target in the trade direction (from current price)
if array.size(tps) > 0
for i = 0 to array.size(tps) - 1
_tp = array.get(tps, i)
cond = side=="Long" ? (_tp > close) : (_tp < close)
if cond
distP = math.abs(_tp - close)
if na(nearestDistPrice) or distP < nearestDistPrice
nearestDistPrice := distP
nearestTP := _tp
if not na(nearestDistPrice) and close != 0
nearestDistPct := (nearestDistPrice / close) * 100.0
float stop = stop_inp > 0 ? stop_inp : na
if not na(wAvgEntry) and not na(stop)
rawRisk = (side=="Long" ? (stop - wAvgEntry) : (wAvgEntry - stop)) / wAvgEntry * 100.0
risk_pct := math.abs(rawRisk)
if not na(wAvgEntry) and not na(nearestTP)
reward_pct := math.abs((side=="Long" ? (nearestTP - wAvgEntry) : (wAvgEntry - nearestTP)) / wAvgEntry * 100.0)
rr := (not na(risk_pct) and not na(reward_pct) and risk_pct != 0) ? reward_pct / risk_pct : na
// ====== Average R:R across all valid targets ======
float rr_avg = na
if not na(wAvgEntry) and not na(stop) and array.size(tps) > 0 and not na(risk_pct) and risk_pct != 0
float sum_rr = 0.0
int cnt_rr = 0
for i = 0 to array.size(tps) - 1
_tp = array.get(tps, i)
bool validDir = side=="Long" ? (_tp > wAvgEntry) : (_tp < wAvgEntry)
if validDir
_reward = math.abs((side=="Long" ? (_tp - wAvgEntry) : (wAvgEntry - _tp)) / wAvgEntry * 100.0)
_rr = _reward / risk_pct
sum_rr += _rr
cnt_rr += 1
rr_avg := cnt_rr > 0 ? (sum_rr / cnt_rr) : na
// ====== Entry/SL/TP Lines ======
var line entryLines = array.new_line(4, na)
for i = 0 to 3
ln = array.get(entryLines, i)
if array.get(ens, i) and array.get(entries, i) > 0
col = array.get(entryCols, i)
ent = array.get(entries, i)
ln := f_stickyHLine(ent, ln, col, 2)
array.set(entryLines, i, ln)
else
if not na(ln)
line.delete(ln)
array.set(entryLines, i, na)
var line slLine = na
if not na(stop)
slLine := f_stickyHLine(stop, slLine, color.new(color.red, 0), 1)
else
if not na(slLine)
line.delete(slLine)
slLine := na
var line tpLine1 = na
var line tpLine2 = na
var line tpLine3 = na
var line tpLine4 = na
var line tpLine5 = na
if use_tp1 and tp1 > 0
tpLine1 := f_stickyHLine(tp1, tpLine1, color.new(color.teal, 0), 1)
else
if not na(tpLine1)
line.delete(tpLine1)
tpLine1 := na
if use_tp2 and tp2 > 0
tpLine2 := f_stickyHLine(tp2, tpLine2, color.new(color.teal, 0), 1)
else
if not na(tpLine2)
line.delete(tpLine2)
tpLine2 := na
if use_tp3 and tp3 > 0
tpLine3 := f_stickyHLine(tp3, tpLine3, color.new(color.teal, 0), 1)
else
if not na(tpLine3)
line.delete(tpLine3)
tpLine3 := na
if use_tp4 and tp4 > 0
tpLine4 := f_stickyHLine(tp4, tpLine4, color.new(color.teal, 0), 1)
else
if not na(tpLine4)
line.delete(tpLine4)
tpLine4 := na
if use_tp5 and tp5 > 0
tpLine5 := f_stickyHLine(tp5, tpLine5, color.new(color.teal, 0), 1)
else
if not na(tpLine5)
line.delete(tpLine5)
tpLine5 := na
// ====== Build HUD Text ======
string txt = ""
// Per-entry rows
for i = 0 to 3
if array.get(ens, i) and array.get(entries, i) > 0
idx = i + 1
ent = array.get(entries, i)
pct = array.get(pcts, i)
pnlq = array.get(pnls, i)
roi = array.get(rois, i)
levX = array.get(levs, i)
txt += (txt=="" ? "" : " ") + "📌 Entry " + str.tostring(idx) + ": " + str.tostring(ent, format.mintick)
txt += " 📊 Live: " + (na(pct) ? "—" : str.tostring(pct, format.mintick) + "%") + " | 💵 " + (na(pnlq) ? "—" : "$" + f_usd_str(pnlq, usd_dp))
txt += " 🧮 ROI(x" + str.tostring(levX) + "): " + (na(roi) ? "—" : str.tostring(roi, format.mintick) + "%")
// Summary or test HUD
if txt != ""
if totalQty > 0
txt += " — — —"
txt += " ⚖️ Weighted Avg Entry: " + str.tostring(wAvgEntry, format.mintick)
if not na(stop)
txt += " ❌ SL: " + str.tostring(stop, format.mintick)
// Nearest target (from current price)
string tpInfo = "—"
if not na(nearestTP)
tpInfo := str.tostring(nearestTP, format.mintick) + (na(nearestDistPct) ? "" : " (Δ " + str.tostring(nearestDistPct, format.mintick) + "%)")
txt += " 🎯 Nearest: " + tpInfo
// R:R (nearest)
if not na(rr)
txt += " 📐 R:R (nearest): " + str.tostring(rr, format.mintick)
// Avg R:R across all valid TPs (by direction from weighted entry)
if not na(rr_avg)
txt += " 📐 Avg R:R (all valid TPs): " + str.tostring(rr_avg, format.mintick)
// Totals
txt += " 🧾 Total P/L: " + "$" + f_usd_str(totalPnlUSD, usd_dp)
txt += " 🧮 Weighted ROI (by Notional): " + (na(totalROIweighted) ? "—" : str.tostring(totalROIweighted, format.mintick) + "%")
else if force_show_hud
txt := "🧪 HUD is active. Fill Entry prices or tick ⚡. Enable TP/SL to see lines."
// ====== HUD Placement (near live price) ======
var label hud = na
atr_val = nz(ta.atr(atr_len), 0.0)
anchor_price = close
y_pos = na(anchor_price) ? na : anchor_price + (atr_val * hud_off_atr)
x_pos_base = bar_index
off = hud_side == "Right of price" ? hud_off_bars : -hud_off_bars
x_pos = lock_to_last_bar ? (barstate.islast ? (x_pos_base + off) : x_pos_base) : (x_pos_base + off)
// Pick label style by side:
// - Right of price → pointer on LEFT edge → style_label_left
// - Left of price → pointer on RIGHT edge → style_label_right
label_style = hud_side == "Right of price" ? label.style_label_left : label.style_label_right
if not na(y_pos) and txt != ""
if na(hud)
hud := label.new(x_pos, y_pos, txt, xloc=xloc.bar_index, style=label_style, textcolor=hud_txtc, color=hud_bg, size=to_size(hud_font))
else
label.set_x(hud, x_pos)
label.set_y(hud, y_pos)
label.set_text(hud, txt)
label.set_textcolor(hud, hud_txtc)
label.set_color(hud, hud_bg)
label.set_style(hud, label_style)
label.set_size(hud, to_size(hud_font))
else
if not na(hud)
label.delete(hud)
hud := na
Candlestick analysis
P/L Panel + Multi Targets (4 Entries) – HUD near Price + Avg R:R//@version=6
indicator("P/L Panel + Multi Targets (4 Entries) – HUD near Price + Avg R:R", overlay=true, max_lines_count=500, max_labels_count=500)
// ====== General ======
side = input.string("Long", "Position Side", options= )
usd_dp = input.int(2, "USD decimals", minval=0, maxval=6)
// ====== HUD Settings ======
hud_font = input.string("large", "HUD font size", options= )
hud_bg = input.color(color.new(color.black, 0), "HUD background color")
hud_txtc = input.color(color.white, "HUD text color")
hud_side = input.string("Right of price", "HUD side", options= )
hud_off_bars = input.int(3, "Horizontal offset (bars)", minval=0, maxval=50)
hud_off_atr = input.float(0.2, "Vertical offset from price (ATR)", step=0.1)
atr_len = input.int(14, "ATR length for vertical offset", minval=1)
lock_to_last_bar = input.bool(true, "Lock HUD to the last bar")
// Show HUD even when there are no entries (test text)
force_show_hud = input.bool(true, "🔍 Show HUD even with no entries")
// ====== Shared SL & Targets ======
stop_inp = input.float(0.0, "Stop Loss (shared, optional)", step=0.0001)
use_tp1 = input.bool(false, "Enable Target 1")
tp1 = input.float(0.0, "Target 1 price", step=0.0001)
use_tp2 = input.bool(false, "Enable Target 2")
tp2 = input.float(0.0, "Target 2 price", step=0.0001)
use_tp3 = input.bool(false, "Enable Target 3")
tp3 = input.float(0.0, "Target 3 price", step=0.0001)
use_tp4 = input.bool(false, "Enable Target 4")
tp4 = input.float(0.0, "Target 4 price", step=0.0001)
use_tp5 = input.bool(false, "Enable Target 5")
tp5 = input.float(0.0, "Target 5 price", step=0.0001)
// ====== Four Independent Entries ======
group1 = "Entry 1"
en1 = input.bool(true, "Enable Entry 1", inline=group1)
lev1 = input.int(10, "Leverage", minval=1, maxval=200, inline=group1)
entry1 = input.float(0.0, "Entry 1 price", step=0.0001)
set_now1 = input.bool(false, "⚡ Set Entry1 = Current Price")
mode1 = input.string("USD (USDT)", "Size unit 1", options= )
sem1 = input.string("Margin (apply leverage)", "Size meaning 1", options= )
size1 = input.float(0.0, "Position size 1", step=0.0001)
baseLev1 = input.bool(false, "Apply leverage to 'Coin Quantity' (1)")
group2 = "Entry 2"
en2 = input.bool(false, "Enable Entry 2", inline=group2)
lev2 = input.int(10, "Leverage", minval=1, maxval=200, inline=group2)
entry2 = input.float(0.0, "Entry 2 price", step=0.0001)
set_now2 = input.bool(false, "⚡ Set Entry2 = Current Price")
mode2 = input.string("USD (USDT)", "Size unit 2", options= )
sem2 = input.string("Margin (apply leverage)", "Size meaning 2", options= )
size2 = input.float(0.0, "Position size 2", step=0.0001)
baseLev2 = input.bool(false, "Apply leverage to 'Coin Quantity' (2)")
group3 = "Entry 3"
en3 = input.bool(false, "Enable Entry 3", inline=group3)
lev3 = input.int(10, "Leverage", minval=1, maxval=200, inline=group3)
entry3 = input.float(0.0, "Entry 3 price", step=0.0001)
set_now3 = input.bool(false, "⚡ Set Entry3 = Current Price")
mode3 = input.string("USD (USDT)", "Size unit 3", options= )
sem3 = input.string("Margin (apply leverage)", "Size meaning 3", options= )
size3 = input.float(0.0, "Position size 3", step=0.0001)
baseLev3 = input.bool(false, "Apply leverage to 'Coin Quantity' (3)")
group4 = "Entry 4"
en4 = input.bool(false, "Enable Entry 4", inline=group4)
lev4 = input.int(10, "Leverage", minval=1, maxval=200, inline=group4)
entry4 = input.float(0.0, "Entry 4 price", step=0.0001)
set_now4 = input.bool(false, "⚡ Set Entry4 = Current Price")
mode4 = input.string("USD (USDT)", "Size unit 4", options= )
sem4 = input.string("Margin (apply leverage)", "Size meaning 4", options= )
size4 = input.float(0.0, "Position size 4", step=0.0001)
baseLev4 = input.bool(false, "Apply leverage to 'Coin Quantity' (4)")
// Quick set entries = current price
entry1 := (en1 and set_now1) ? close : entry1
entry2 := (en2 and set_now2) ? close : entry2
entry3 := (en3 and set_now3) ? close : entry3
entry4 := (en4 and set_now4) ? close : entry4
// ====== Helpers ======
to_size(s) =>
s == "tiny" ? size.tiny : s == "small" ? size.small : s == "normal" ? size.normal : s == "large" ? size.large : size.huge
f_usd_str(_val, _decimals) =>
na(_val) ? "—" : str.tostring(math.round(_val * math.pow(10, _decimals)) / math.pow(10, _decimals))
f_qty_base(mode, sem, size, entry, baseLev, lev) =>
float _qty = na
if mode == "USD (USDT)"
_qty := (size > 0 and entry > 0) ? ((sem == "Margin (apply leverage)" ? size * lev : size) / entry) : na
else
_qty := size > 0 ? (baseLev ? size * lev : size) : na
_qty
f_notional_quote(mode, sem, size, entry, lev, baseLev) =>
if mode == "USD (USDT)"
sem == "Margin (apply leverage)" ? size * lev : size
else
(baseLev ? size * lev : size) * entry
f_pnl_quote(side, entry, qty) =>
na(qty) or na(entry) ? na : (side=="Long" ? (close - entry) : (entry - close)) * qty
f_pct(side, entry) =>
na(entry) ? na : ((close - entry) / entry * 100.0) * (side=="Long" ? 1 : -1)
f_roi_pct(side, entry, lev) =>
na(entry) ? na : f_pct(side, entry) * lev
// NOTE: _lineIn must be a line, not a float
f_stickyHLine(_price, _lineIn, _color, _width) =>
var line _out = na
_out := _lineIn
if na(_out)
_out := line.new(bar_index-1, _price, bar_index+1, _price, xloc=xloc.bar_index, extend=extend.both, width=_width, style=line.style_dashed, color=_color)
else
line.set_xy1(_out, bar_index-1, _price)
line.set_xy2(_out, bar_index+1, _price)
line.set_color(_out, _color)
line.set_width(_out, _width)
_out
// ====== 4 Entries Calculations ======
var color entryCols = array.from(color.new(color.yellow, 0), color.new(color.orange, 0), color.new(color.teal, 0), color.new(color.fuchsia, 0))
bool ens = array.from(en1, en2, en3, en4)
float entries = array.from(entry1, entry2, entry3, entry4)
int levs = array.from(lev1, lev2, lev3, lev4)
string modes = array.from(mode1, mode2, mode3, mode4)
string sems = array.from(sem1, sem2, sem3, sem4)
float sizes = array.from(size1, size2, size3, size4)
bool baseLevs = array.from(baseLev1, baseLev2, baseLev3, baseLev4)
float qtys = array.new_float(4, na)
float pnls = array.new_float(4, na)
float pcts = array.new_float(4, na)
float rois = array.new_float(4, na)
float notionals = array.new_float(4, na)
for i = 0 to 3
if array.get(ens, i) and array.get(entries, i) > 0
ent = array.get(entries, i)
levX = array.get(levs, i)
modeX= array.get(modes, i)
semX = array.get(sems, i)
sizeX= array.get(sizes, i)
bLev = array.get(baseLevs, i)
qty = f_qty_base(modeX, semX, sizeX, ent, bLev, levX)
array.set(qtys, i, qty)
pnlq = f_pnl_quote(side, ent, qty)
array.set(pnls, i, pnlq)
pct = f_pct(side, ent)
array.set(pcts, i, pct)
roi = f_roi_pct(side, ent, levX)
array.set(rois, i, roi)
notq = f_notional_quote(modeX, semX, sizeX, ent, levX, bLev)
array.set(notionals, i, notq)
// ====== Totals & Weighted Avg Entry ======
float totalPnlUSD = 0.0
float totalNotional = 0.0
float totalQty = 0.0
float wAvgEntry = na
for i = 0 to 3
if not na(array.get(pnls, i))
totalPnlUSD += array.get(pnls, i)
if not na(array.get(notionals, i))
totalNotional += array.get(notionals, i)
if not na(array.get(qtys, i)) and array.get(entries, i) > 0
totalQty += array.get(qtys, i)
if totalQty > 0
num = 0.0
for i = 0 to 3
qi = array.get(qtys, i)
ei = array.get(entries, i)
if not na(qi) and ei > 0
num += qi * ei
wAvgEntry := num / totalQty
totalROIweighted = totalNotional > 0 ? (totalPnlUSD / totalNotional) * 100.0 : na
// ====== Nearest TP & R:R ======
float nearestTP = na
float nearestDistPrice = na
float nearestDistPct = na
float risk_pct = na
float reward_pct = na
float rr = na
var float tps = array.new_float()
array.clear(tps)
if use_tp1 and tp1 > 0
array.push(tps, tp1)
if use_tp2 and tp2 > 0
array.push(tps, tp2)
if use_tp3 and tp3 > 0
array.push(tps, tp3)
if use_tp4 and tp4 > 0
array.push(tps, tp4)
if use_tp5 and tp5 > 0
array.push(tps, tp5)
// nearest target in the trade direction (from current price)
if array.size(tps) > 0
for i = 0 to array.size(tps) - 1
_tp = array.get(tps, i)
cond = side=="Long" ? (_tp > close) : (_tp < close)
if cond
distP = math.abs(_tp - close)
if na(nearestDistPrice) or distP < nearestDistPrice
nearestDistPrice := distP
nearestTP := _tp
if not na(nearestDistPrice) and close != 0
nearestDistPct := (nearestDistPrice / close) * 100.0
float stop = stop_inp > 0 ? stop_inp : na
if not na(wAvgEntry) and not na(stop)
rawRisk = (side=="Long" ? (stop - wAvgEntry) : (wAvgEntry - stop)) / wAvgEntry * 100.0
risk_pct := math.abs(rawRisk)
if not na(wAvgEntry) and not na(nearestTP)
reward_pct := math.abs((side=="Long" ? (nearestTP - wAvgEntry) : (wAvgEntry - nearestTP)) / wAvgEntry * 100.0)
rr := (not na(risk_pct) and not na(reward_pct) and risk_pct != 0) ? reward_pct / risk_pct : na
// ====== Average R:R across all valid targets ======
float rr_avg = na
if not na(wAvgEntry) and not na(stop) and array.size(tps) > 0 and not na(risk_pct) and risk_pct != 0
float sum_rr = 0.0
int cnt_rr = 0
for i = 0 to array.size(tps) - 1
_tp = array.get(tps, i)
bool validDir = side=="Long" ? (_tp > wAvgEntry) : (_tp < wAvgEntry)
if validDir
_reward = math.abs((side=="Long" ? (_tp - wAvgEntry) : (wAvgEntry - _tp)) / wAvgEntry * 100.0)
_rr = _reward / risk_pct
sum_rr += _rr
cnt_rr += 1
rr_avg := cnt_rr > 0 ? (sum_rr / cnt_rr) : na
// ====== Entry/SL/TP Lines ======
var line entryLines = array.new_line(4, na)
for i = 0 to 3
ln = array.get(entryLines, i)
if array.get(ens, i) and array.get(entries, i) > 0
col = array.get(entryCols, i)
ent = array.get(entries, i)
ln := f_stickyHLine(ent, ln, col, 2)
array.set(entryLines, i, ln)
else
if not na(ln)
line.delete(ln)
array.set(entryLines, i, na)
var line slLine = na
if not na(stop)
slLine := f_stickyHLine(stop, slLine, color.new(color.red, 0), 1)
else
if not na(slLine)
line.delete(slLine)
slLine := na
var line tpLine1 = na
var line tpLine2 = na
var line tpLine3 = na
var line tpLine4 = na
var line tpLine5 = na
if use_tp1 and tp1 > 0
tpLine1 := f_stickyHLine(tp1, tpLine1, color.new(color.teal, 0), 1)
else
if not na(tpLine1)
line.delete(tpLine1)
tpLine1 := na
if use_tp2 and tp2 > 0
tpLine2 := f_stickyHLine(tp2, tpLine2, color.new(color.teal, 0), 1)
else
if not na(tpLine2)
line.delete(tpLine2)
tpLine2 := na
if use_tp3 and tp3 > 0
tpLine3 := f_stickyHLine(tp3, tpLine3, color.new(color.teal, 0), 1)
else
if not na(tpLine3)
line.delete(tpLine3)
tpLine3 := na
if use_tp4 and tp4 > 0
tpLine4 := f_stickyHLine(tp4, tpLine4, color.new(color.teal, 0), 1)
else
if not na(tpLine4)
line.delete(tpLine4)
tpLine4 := na
if use_tp5 and tp5 > 0
tpLine5 := f_stickyHLine(tp5, tpLine5, color.new(color.teal, 0), 1)
else
if not na(tpLine5)
line.delete(tpLine5)
tpLine5 := na
// ====== Build HUD Text ======
string txt = ""
// Per-entry rows
for i = 0 to 3
if array.get(ens, i) and array.get(entries, i) > 0
idx = i + 1
ent = array.get(entries, i)
pct = array.get(pcts, i)
pnlq = array.get(pnls, i)
roi = array.get(rois, i)
levX = array.get(levs, i)
txt += (txt=="" ? "" : " ") + "📌 Entry " + str.tostring(idx) + ": " + str.tostring(ent, format.mintick)
txt += " 📊 Live: " + (na(pct) ? "—" : str.tostring(pct, format.mintick) + "%") + " | 💵 " + (na(pnlq) ? "—" : "$" + f_usd_str(pnlq, usd_dp))
txt += " 🧮 ROI(x" + str.tostring(levX) + "): " + (na(roi) ? "—" : str.tostring(roi, format.mintick) + "%")
// Summary or test HUD
if txt != ""
if totalQty > 0
txt += " — — —"
txt += " ⚖️ Weighted Avg Entry: " + str.tostring(wAvgEntry, format.mintick)
if not na(stop)
txt += " ❌ SL: " + str.tostring(stop, format.mintick)
// Nearest target (from current price)
string tpInfo = "—"
if not na(nearestTP)
tpInfo := str.tostring(nearestTP, format.mintick) + (na(nearestDistPct) ? "" : " (Δ " + str.tostring(nearestDistPct, format.mintick) + "%)")
txt += " 🎯 Nearest: " + tpInfo
// R:R (nearest)
if not na(rr)
txt += " 📐 R:R (nearest): " + str.tostring(rr, format.mintick)
// Avg R:R across all valid TPs (by direction from weighted entry)
if not na(rr_avg)
txt += " 📐 Avg R:R (all valid TPs): " + str.tostring(rr_avg, format.mintick)
// Totals
txt += " 🧾 Total P/L: " + "$" + f_usd_str(totalPnlUSD, usd_dp)
txt += " 🧮 Weighted ROI (by Notional): " + (na(totalROIweighted) ? "—" : str.tostring(totalROIweighted, format.mintick) + "%")
else if force_show_hud
txt := "🧪 HUD is active. Fill Entry prices or tick ⚡. Enable TP/SL to see lines."
// ====== HUD Placement (near live price) ======
var label hud = na
atr_val = nz(ta.atr(atr_len), 0.0)
anchor_price = close
y_pos = na(anchor_price) ? na : anchor_price + (atr_val * hud_off_atr)
x_pos_base = bar_index
off = hud_side == "Right of price" ? hud_off_bars : -hud_off_bars
x_pos = lock_to_last_bar ? (barstate.islast ? (x_pos_base + off) : x_pos_base) : (x_pos_base + off)
// Pick label style by side:
// - Right of price → pointer on LEFT edge → style_label_left
// - Left of price → pointer on RIGHT edge → style_label_right
label_style = hud_side == "Right of price" ? label.style_label_left : label.style_label_right
if not na(y_pos) and txt != ""
if na(hud)
hud := label.new(x_pos, y_pos, txt, xloc=xloc.bar_index, style=label_style, textcolor=hud_txtc, color=hud_bg, size=to_size(hud_font))
else
label.set_x(hud, x_pos)
label.set_y(hud, y_pos)
label.set_text(hud, txt)
label.set_textcolor(hud, hud_txtc)
label.set_color(hud, hud_bg)
label.set_style(hud, label_style)
label.set_size(hud, to_size(hud_font))
else
if not na(hud)
label.delete(hud)
hud := na
TWS - ATR, VWAP, PDHLC, EMAThis indicator is combination of many indicator. Like ATR, VWAP, Previous day low, high, close & EMA.
پنل سود/زیان + چند تارگت R:R//@version=6
indicator("پنل سود/زیان + چند تارگت (۴ ورود مستقل) - پنل چپ نزدیک قیمت + میانگین R:R", overlay=true, max_lines_count=500, max_labels_count=500)
// ====== تنظیمات عمومی ======
side = input.string("لانگ", "نوع پوزیشن", options= )
usd_dp = input.int(2, "تعداد اعشار نمایش دلار", minval=0, maxval=6)
// ====== تنظیمات پنل ======
hud_font = input.string("large", "اندازۀ فونت پنل", options= )
hud_bg = input.color(color.new(color.black, 0), "رنگ پسزمینه پنل")
hud_txtc = input.color(color.white, "رنگ متن پنل")
// محل پنل: کمی «چپِ» آخرین کندل + کمی فاصله عمودی از قیمت
hud_off_bars = input.int(3, "فاصلۀ افقی از قیمت به سمت چپ (تعداد کندل، فقط روی آخرین کندل)", minval=0, maxval=50)
hud_off_atr = input.float(0.2, "فاصلۀ عمودی از قیمت (ATR)", step=0.1)
atr_len = input.int(14, "طول ATR برای فاصله عمودی", minval=1)
// نمایش اجباری پنل حتی بدون ورود
force_show_hud = input.bool(true, "🔍 نمایش اجباری پنل حتی بدون ورود")
// ====== حد ضرر و تارگتهای مشترک ======
stop_inp = input.float(0.0, "حد ضرر (مشترک، اختیاری)", step=0.0001)
use_tp1 = input.bool(false, "فعالسازی تارگت ۱")
tp1 = input.float(0.0, "قیمت تارگت ۱", step=0.0001)
use_tp2 = input.bool(false, "فعالسازی تارگت ۲")
tp2 = input.float(0.0, "قیمت تارگت ۲", step=0.0001)
use_tp3 = input.bool(false, "فعالسازی تارگت ۳")
tp3 = input.float(0.0, "قیمت تارگت ۳", step=0.0001)
use_tp4 = input.bool(false, "فعالسازی تارگت ۴")
tp4 = input.float(0.0, "قیمت تارگت ۴", step=0.0001)
use_tp5 = input.bool(false, "فعالسازی تارگت ۵")
tp5 = input.float(0.0, "قیمت تارگت ۵", step=0.0001)
// ====== ورودیهای ۴ ورود مستقل ======
group1 = "ورود ۱"
en1 = input.bool(true, "فعالسازی ورود ۱", inline=group1)
lev1 = input.int(10, "لوریج", minval=1, maxval=200, inline=group1)
entry1 = input.float(0.0, "قیمت ورود ۱", step=0.0001)
set_now1 = input.bool(false, "⚡ ثبت ورود۱ = قیمت فعلی")
mode1 = input.string("دلاری (USDT)", "واحد اندازه ۱", options= )
sem1 = input.string("مارجین (اعمال لوریج)", "تعبیر اندازه ۱", options= )
size1 = input.float(0.0, "اندازه پوزیشن ۱", step=0.0001)
baseLev1 = input.bool(false, "اعمال لوریج روی حالت «تعداد کوین» (۱)")
group2 = "ورود ۲"
en2 = input.bool(false, "فعالسازی ورود ۲", inline=group2)
lev2 = input.int(10, "لوریج", minval=1, maxval=200, inline=group2)
entry2 = input.float(0.0, "قیمت ورود ۲", step=0.0001)
set_now2 = input.bool(false, "⚡ ثبت ورود۲ = قیمت فعلی")
mode2 = input.string("دلاری (USDT)", "واحد اندازه ۲", options= )
sem2 = input.string("مارجین (اعمال لوریج)", "تعبیر اندازه ۲", options= )
size2 = input.float(0.0, "اندازه پوزیشن ۲", step=0.0001)
baseLev2 = input.bool(false, "اعمال لوریج روی حالت «تعداد کوین» (۲)")
group3 = "ورود ۳"
en3 = input.bool(false, "فعالسازی ورود ۳", inline=group3)
lev3 = input.int(10, "لوریج", minval=1, maxval=200, inline=group3)
entry3 = input.float(0.0, "قیمت ورود ۳", step=0.0001)
set_now3 = input.bool(false, "⚡ ثبت ورود۳ = قیمت فعلی")
mode3 = input.string("دلاری (USDT)", "واحد اندازه ۳", options= )
sem3 = input.string("مارجین (اعمال لوریج)", "تعبیر اندازه ۳", options= )
size3 = input.float(0.0, "اندازه پوزیشن ۳", step=0.0001)
baseLev3 = input.bool(false, "اعمال لوریج روی حالت «تعداد کوین» (۳)")
group4 = "ورود ۴"
en4 = input.bool(false, "فعالسازی ورود ۴", inline=group4)
lev4 = input.int(10, "لوریج", minval=1, maxval=200, inline=group4)
entry4 = input.float(0.0, "قیمت ورود ۴", step=0.0001)
set_now4 = input.bool(false, "⚡ ثبت ورود۴ = قیمت فعلی")
mode4 = input.string("دلاری (USDT)", "واحد اندازه ۴", options= )
sem4 = input.string("مارجین (اعمال لوریج)", "تعبیر اندازه ۴", options= )
size4 = input.float(0.0, "اندازه پوزیشن ۴", step=0.0001)
baseLev4 = input.bool(false, "اعمال لوریج روی حالت «تعداد کوین» (۴)")
// ثبت سریع ورود = قیمت فعلی
entry1 := (en1 and set_now1) ? close : entry1
entry2 := (en2 and set_now2) ? close : entry2
entry3 := (en3 and set_now3) ? close : entry3
entry4 := (en4 and set_now4) ? close : entry4
// ====== کمکتابعها ======
to_size(s) =>
s == "tiny" ? size.tiny : s == "small" ? size.small : s == "normal" ? size.normal : s == "large" ? size.large : size.huge
f_usd_str(_val, _decimals) =>
na(_val) ? "—" : str.tostring(math.round(_val * math.pow(10, _decimals)) / math.pow(10, _decimals))
f_qty_base(mode, sem, size, entry, baseLev, lev) =>
float _qty = na
if mode == "دلاری (USDT)"
_qty := (size > 0 and entry > 0) ? ((sem == "مارجین (اعمال لوریج)" ? size * lev : size) / entry) : na
else
_qty := size > 0 ? (baseLev ? size * lev : size) : na
_qty
f_notional_quote(mode, sem, size, entry, lev, baseLev) =>
if mode == "دلاری (USDT)"
sem == "مارجین (اعمال لوریج)" ? size * lev : size
else
(baseLev ? size * lev : size) * entry
f_pnl_quote(side, entry, qty) =>
na(qty) or na(entry) ? na : (side=="لانگ" ? (close - entry) : (entry - close)) * qty
f_pct(side, entry) =>
na(entry) ? na : ((close - entry) / entry * 100.0) * (side=="لانگ" ? 1 : -1)
f_roi_pct(side, entry, lev) =>
na(entry) ? na : f_pct(side, entry) * lev
f_stickyHLine(_price, _lineIn, _color, _width) =>
var line _out = na
_out := _lineIn
if na(_out)
_out := line.new(bar_index-1, _price, bar_index+1, _price, xloc=xloc.bar_index, extend=extend.both, width=_width, style=line.style_dashed, color=_color)
else
line.set_xy1(_out, bar_index-1, _price)
line.set_xy2(_out, bar_index+1, _price)
line.set_color(_out, _color)
line.set_width(_out, _width)
_out
// ====== محاسبات ۴ ورود ======
var color entryCols = array.from(color.new(color.yellow, 0), color.new(color.orange, 0), color.new(color.teal, 0), color.new(color.fuchsia, 0))
bool ens = array.from(en1, en2, en3, en4)
float entries = array.from(entry1, entry2, entry3, entry4)
int levs = array.from(lev1, lev2, lev3, lev4)
string modes = array.from(mode1, mode2, mode3, mode4)
string sems = array.from(sem1, sem2, sem3, sem4)
float sizes = array.from(size1, size2, size3, size4)
bool baseLevs = array.from(baseLev1, baseLev2, baseLev3, baseLev4)
float qtys = array.new_float(4, na)
float pnls = array.new_float(4, na)
float pcts = array.new_float(4, na)
float rois = array.new_float(4, na)
float notionals = array.new_float(4, na)
for i = 0 to 3
if array.get(ens, i) and array.get(entries, i) > 0
ent = array.get(entries, i)
levX = array.get(levs, i)
modeX= array.get(modes, i)
semX = array.get(sems, i)
sizeX= array.get(sizes, i)
bLev = array.get(baseLevs, i)
qty = f_qty_base(modeX, semX, sizeX, ent, bLev, levX)
array.set(qtys, i, qty)
pnlq = f_pnl_quote(side, ent, qty)
array.set(pnls, i, pnlq)
pct = f_pct(side, ent)
array.set(pcts, i, pct)
roi = f_roi_pct(side, ent, levX)
array.set(rois, i, roi)
notq = f_notional_quote(modeX, semX, sizeX, ent, levX, bLev)
array.set(notionals, i, notq)
// ====== مجموع و میانگین ورود وزنی ======
float totalPnlUSD = 0.0
float totalNotional = 0.0
float totalQty = 0.0
float wAvgEntry = na
for i = 0 to 3
if not na(array.get(pnls, i))
totalPnlUSD += array.get(pnls, i)
if not na(array.get(notionals, i))
totalNotional += array.get(notionals, i)
if not na(array.get(qtys, i)) and array.get(entries, i) > 0
totalQty += array.get(qtys, i)
if totalQty > 0
num = 0.0
for i = 0 to 3
qi = array.get(qtys, i)
ei = array.get(entries, i)
if not na(qi) and ei > 0
num += qi * ei
wAvgEntry := num / totalQty
totalROIweighted = totalNotional > 0 ? (totalPnlUSD / totalNotional) * 100.0 : na
// ====== نزدیکترین تارگت و R:R ======
float nearestTP = na
float nearestDistPrice = na
float nearestDistPct = na
float risk_pct = na
float reward_pct = na
float rr = na
var float tps = array.new_float()
array.clear(tps)
if use_tp1 and tp1 > 0
array.push(tps, tp1)
if use_tp2 and tp2 > 0
array.push(tps, tp2)
if use_tp3 and tp3 > 0
array.push(tps, tp3)
if use_tp4 and tp4 > 0
array.push(tps, tp4)
if use_tp5 and tp5 > 0
array.push(tps, tp5)
// نزدیکترین تارگت همسو با جهت
if array.size(tps) > 0
for i = 0 to array.size(tps) - 1
_tp = array.get(tps, i)
cond = side=="لانگ" ? (_tp > close) : (_tp < close)
if cond
distP = math.abs(_tp - close)
if na(nearestDistPrice) or distP < nearestDistPrice
nearestDistPrice := distP
nearestTP := _tp
if not na(nearestDistPrice) and close != 0
nearestDistPct := (nearestDistPrice / close) * 100.0
float stop = stop_inp > 0 ? stop_inp : na
if not na(wAvgEntry) and not na(stop)
rawRisk = (side=="لانگ" ? (stop - wAvgEntry) : (wAvgEntry - stop)) / wAvgEntry * 100.0
risk_pct := math.abs(rawRisk)
if not na(wAvgEntry) and not na(nearestTP)
reward_pct := math.abs((side=="لانگ" ? (nearestTP - wAvgEntry) : (wAvgEntry - nearestTP)) / wAvgEntry * 100.0)
rr := (not na(risk_pct) and not na(reward_pct) and risk_pct != 0) ? reward_pct / risk_pct : na
// ====== «میانگین R:R» روی همه تارگتهای معتبر ======
float rr_avg = na
if not na(wAvgEntry) and not na(stop) and array.size(tps) > 0 and not na(risk_pct) and risk_pct != 0
float sum_rr = 0.0
int cnt_rr = 0
for i = 0 to array.size(tps) - 1
_tp = array.get(tps, i)
bool validDir = side=="لانگ" ? (_tp > wAvgEntry) : (_tp < wAvgEntry)
if validDir
_reward = math.abs((side=="لانگ" ? (_tp - wAvgEntry) : (wAvgEntry - _tp)) / wAvgEntry * 100.0)
_rr = _reward / risk_pct
sum_rr += _rr
cnt_rr += 1
rr_avg := cnt_rr > 0 ? (sum_rr / cnt_rr) : na
// ====== خطوط ورود/SL/TP ======
var line entryLines = array.new_line(4, na)
for i = 0 to 3
ln = array.get(entryLines, i)
if array.get(ens, i) and array.get(entries, i) > 0
col = array.get(entryCols, i)
ent = array.get(entries, i)
ln := f_stickyHLine(ent, ln, col, 2)
array.set(entryLines, i, ln)
else
if not na(ln)
line.delete(ln)
array.set(entryLines, i, na)
var line slLine = na
if not na(stop)
slLine := f_stickyHLine(stop, slLine, color.new(color.red, 0), 1)
else
if not na(slLine)
line.delete(slLine)
slLine := na
var line tpLine1 = na
var line tpLine2 = na
var line tpLine3 = na
var line tpLine4 = na
var line tpLine5 = na
if use_tp1 and tp1 > 0
tpLine1 := f_stickyHLine(tp1, tpLine1, color.new(color.teal, 0), 1)
else
if not na(tpLine1)
line.delete(tpLine1)
tpLine1 := na
if use_tp2 and tp2 > 0
tpLine2 := f_stickyHLine(tp2, tpLine2, color.new(color.teal, 0), 1)
else
if not na(tpLine2)
line.delete(tpLine2)
tpLine2 := na
if use_tp3 and tp3 > 0
tpLine3 := f_stickyHLine(tp3, tpLine3, color.new(color.teal, 0), 1)
else
if not na(tpLine3)
line.delete(tpLine3)
tpLine3 := na
if use_tp4 and tp4 > 0
tpLine4 := f_stickyHLine(tp4, tpLine4, color.new(color.teal, 0), 1)
else
if not na(tpLine4)
line.delete(tpLine4)
tpLine4 := na
if use_tp5 and tp5 > 0
tpLine5 := f_stickyHLine(tp5, tpLine5, color.new(color.teal, 0), 1)
else
if not na(tpLine5)
line.delete(tpLine5)
tpLine5 := na
// ====== ساخت متن پنل ======
string txt = ""
// ردیفهای هر ورود
for i = 0 to 3
if array.get(ens, i) and array.get(entries, i) > 0
idx = i + 1
ent = array.get(entries, i)
pct = array.get(pcts, i)
pnlq = array.get(pnls, i)
roi = array.get(rois, i)
levX = array.get(levs, i)
txt += (txt=="" ? "" : " ") + "📌 ورود " + str.tostring(idx) + ": " + str.tostring(ent, format.mintick)
txt += " 📊 لحظهای: " + (na(pct) ? "—" : str.tostring(pct, format.mintick) + "%") + " | 💵 " + (na(pnlq) ? "—" : "$" + f_usd_str(pnlq, usd_dp))
txt += " 🧮 ROI(x" + str.tostring(levX) + "): " + (na(roi) ? "—" : str.tostring(roi, format.mintick) + "%")
// خلاصه پایانی یا پنل تست
if txt != ""
if totalQty > 0
txt += " — — —"
txt += " ⚖️ میانگین ورود وزنی: " + str.tostring(wAvgEntry, format.mintick)
if not na(stop)
txt += " ❌ SL: " + str.tostring(stop, format.mintick)
// نزدیکترین تارگت
string tpInfo = "—"
if not na(nearestTP)
tpInfo := str.tostring(nearestTP, format.mintick) + (na(nearestDistPct) ? "" : " (Δ " + str.tostring(nearestDistPct, format.mintick) + "%)")
txt += " 🎯 نزدیکترین: " + tpInfo
// R:R نزدیکترین
if not na(rr)
txt += " 📐 R:R نزدیکترین: " + str.tostring(rr, format.mintick)
// میانگین R:R روی همه تارگتهای معتبر
if not na(rr_avg)
txt += " 📐 میانگین R:R (همۀ تارگتهای معتبر): " + str.tostring(rr_avg, format.mintick)
// مجموعها
txt += " 🧾 مجموع سود/زیان: " + "$" + f_usd_str(totalPnlUSD, usd_dp)
txt += " 🧮 ROĪ وزنی (بر اساس ناتیونال): " + (na(totalROIweighted) ? "—" : str.tostring(totalROIweighted, format.mintick) + "%")
else if force_show_hud
txt := "🧪 پنل فعال است. از فیلدهای «قیمت ورود» استفاده کن یا تیکهای ⚡ را بزن. برای دیدن TP/SL خطوط، تیکهای مربوطه را فعال کن."
// ====== HUD (پنل سمت چپ، نوک اشاره نزدیک قیمت لحظهای) ======
// ====== HUD (پنل سمت راست، نوک اشاره نزدیک قیمت لحظهای) ======
var label hud = na
atr_val = ta.atr(atr_len)
// لنگر عمودی روی قیمت لحظهای با کمی فاصله عمودی
anchor_price = close
y_pos = na(anchor_price) ? na : anchor_price + (atr_val * hud_off_atr)
// فقط روی آخرین کندل، چند بار به «راست» میبریم تا نوک پنل نزدیک کندل باشد
x_pos_base = bar_index
x_pos = barstate.islast ? (x_pos_base + hud_off_bars) : x_pos_base
if not na(y_pos) and txt != ""
if na(hud)
// ⚠️ style_label_left = نوک پنل سمت چپ است ⇒ متن به راست باز میشود ⇒ کل پنل در «راستِ» قیمت قرار میگیرد
hud := label.new(x_pos, y_pos, txt,xloc=xloc.bar_index,style=label.style_label_left, textcolor=hud_txtc, color=hud_bg, size=to_size(hud_font))
else
label.set_x(hud, x_pos)
label.set_y(hud, y_pos)
label.set_text(hud, txt)
label.set_textcolor(hud, hud_txtc)
label.set_color(hud, hud_bg)
label.set_style(hud, label.style_label_left)
label.set_size(hud, to_size(hud_font))
else
if not na(hud)
label.delete(hud)
hud := na
PDT AI✅ Features
Multi-indicator fusion: RSI + MACD + EMA + higher timeframe RSI
Signal strength (%): Each signal gets a confidence score (0–100)
Dynamic ATR-based targets and stops
Alerts: Buy/Sell triggers for real-time notifications
Fully customizable inputs
PumpC PAC & MAsPumpC – PAC & MAs (Open Source)
A complete Price Action Candles (PAC) toolkit combining classical price action patterns (Fair Value Gaps, Inside Bars, Hammers, Inverted Hammers, and Volume Imbalances) with a flexible Moving Averages (MAs) module and an advanced bar-coloring system.
This script highlights supply/demand inefficiencies and micro-patterns with forward-extending boxes, recolors zones when mitigated, qualifies patterns with a global High-Volume filter, and ships with ready-to-use alerts. It works across intraday through swing trading on any market (e.g., NASDAQ:QQQ , $CME:ES1!, FX:EURUSD , BITSTAMP:BTCUSD ).
This is an open-source script. The description is detailed so users understand what the script does, how it works, and how to use it. It makes no performance claims and does not provide trade advice.
Acknowledgment & Credits
This script originates from the structural and box-handling logic found in the Super OrderBlock / FVG / BoS Tools by makuchaku & eFe. Their pioneering framework provided the base methods for managing arrays of boxes, extending zones forward, and recoloring once mitigated.
Building on that foundation, I have substantially expanded and adapted the code to create a unified Price Action Candles toolkit . This includes Al Brooks–inspired PAC logic, additional patterns like Inside Bars, Hammers, Inverted Hammers, and the new Volume Imbalance module, along with strong-bar coloring, close-threshold detection, a flexible global High-Volume filter, and a multi-timeframe Moving Averages system.
What it does
Fair Value Gaps (FVG) : Detects 3-bar displacement gaps, plots forward-extending boxes, and optionally recolors them once mitigated.
Inside Bars (IB) : Highlights bars fully contained within the prior candle’s range, with optional high-volume filter.
Hammers (H) & Inverted Hammers (IH) : Identifies rejection candles using configurable body/upper/lower wick thresholds. High-volume qualification optional.
Volume Imbalances (VI) : Detects inter-body gaps where one candle’s body does not overlap the prior candle’s body. Boxes extend forward until wick-based mitigation occurs (only after the two-bar formation completes). Alerts available for creation and mitigation.
Mitigation Recolor : Each pattern can flip to a mitigated color once price trades back through its vertical zone.
Moving Averages (MAs) : Four configurable EMAs/SMAs, with per-MA timeframe, length, color, and clutter-free plotting rules.
Strong Bar Coloring : Highlights bullish/bearish engulfing reversals with different colors for high-volume vs low-volume cases.
Close Threshold Bars : Marks candles that close in the top or bottom portion of their range, even if the body is small. Helps spot continuation pressure before a full trend bar forms.
Alerts : Notifications available for FVG+, FVG−, IB, H, IH, VI creation, and VI mitigation.
Connection to Al Brooks’ PAC teachings
This script reflects Al Brooks’ Price Action Candle methodology. PAC patterns like Inside Bars, Hammers, and Inverted Hammers are not trade signals on their own—they gain meaning in context of trend, failed breakouts, and effort vs. result.
By layering in volume imbalances, strong-bar reversals, and volume filters, this script focuses attention on the PACs that show true participation and conviction, aligning with Brooks’ emphasis on reading crowd psychology through price action.
Why the High-Volume filter matters
Volume is a key proxy for conviction. A PAC or VI formed on light volume can be misleading noise; one formed on above-average volume carries more weight.
Elevates Inside Bars that show absorption/compression with heavy activity.
Distinguishes Hammers that reject price aggressively vs. weak drifts.
Filters Inverted Hammers to emphasize true supply pressure.
Highlights VI zones where institutional order flow left inefficiencies.
Differentiates strong engulfing reversals from weaker, low-participation moves.
Inputs & Customization
Inputs are grouped logically for fast configuration:
High-Volume Filter : Global lookback & multiple, per-pattern toggles.
FVG : Visibility, mitigated recolor, box style/transparency, label controls.
IB : Visibility, require high volume, mitigated recolor, colors, label settings.
Hammer / IH : Visibility, require high volume, mitigated recolor, wick/body thresholds.
VI : Visibility, require high volume, mitigated recolor, box style, labels, mitigation alerts.
Strong Bars : Enable/disable, separate colors for high-volume and low-volume outcomes.
Close Threshold Bars : Customizable close thresholds, labels, optional count markers.
MAs : EMA/SMA type, per-MA toggle, length, timeframe, color.
Alerts
New Bullish FVG (+)
New Bearish FVG (−)
New Inside Bar (IB)
New Hammer (H)
New Inverted Hammer (IH)
New Volume Imbalance (VI)
VI Mitigated
Strong Bullish Engulfing / Bearish Engulfing (high- and low-volume variants)
Suggested workflow
Choose your market & timeframe (script works across equities, futures, FX, crypto).
Toggle only the PACs you actually trade. Assign distinct colors for clarity.
Use MAs for directional bias and higher timeframe structure.
Enable High-Volume filters when you want to emphasize conviction.
Watch mitigation recolors to see which levels/zones have been interacted with.
Use alerts selectively for setups aligned with your plan.
Originality
Builds upon Super OrderBlock / FVG / BoS Tools (makuchaku & eFe) for FVG/box framework.
Expanded into a unified PAC toolkit including IB, H, IH, and VI patterns.
Brooks-inspired design: Patterns contextualized with volume and trend, not isolated.
Flexible high-volume gating with per-pattern toggles.
New VI integration with wick-based mitigation.
Strong Bar Coloring differentiates conviction vs weak reversals.
MTF-aware MAs prevent clutter while providing structure.
Open-source: Transparent for learning, editing, and extension.
Disclaimer
For educational and informational purposes only. This script is not financial advice. Trading carries risk—always test thoroughly before live use.
Wick Box: Hammer + Engulfing |Thaowick boxes and hammer box drawings for engulfing and hammer candles bullish and bearish
the best indicator for spotting reversal s
Emre AOI Zonen Daily & Weekly (mit Alerts, max 60 Pips)This TradingView indicator automatically highlights Areas of Interest (AOI) for Forex or other markets on Daily and Weekly timeframes. It identifies zones based on the high and low of the previous period, but only includes zones with a width of 60 pips or less.
Features:
Daily AOI Zones in blue, Weekly AOI Zones in yellow with 20% opacity, so candlesticks remain visible.
Persistent zones: AOI boxes stay on the chart until the price breaks the zone.
Multiple zones: Supports storing multiple Daily and Weekly AOIs simultaneously.
Break Alerts: Sends alerts whenever a Daily or Weekly AOI is broken, helping traders spot key levels in real-time.
Fully automated: No manual drawing needed; zones are updated and extended automatically.
Use Case:
Ideal for traders using a top-down approach, combining Weekly trend analysis with Daily entry signals. Helps identify support/resistance, supply/demand zones, and critical price levels efficiently.
Session Based Liquidity# Session Based Liquidity Indicator - Educational Open Source
## 📊 Overview
The Session Based Liquidity indicator is a comprehensive educational tool designed to help traders understand and visualize liquidity concepts across major trading sessions. This indicator identifies Buy-Side Liquidity (BSL) and Sell-Side Liquidity (SSL) levels created during Asia, London, and New York trading sessions, providing insights into institutional order flow and potential market reversal zones.
## 🎯 Key Features
### 📈 Multi-Session Tracking
- **Asia Session**: Tokyo/Sydney overlap (20:00-02:00 EST)
- **London Session**: European markets (03:00-07:30 EST)
- **New York Session**: US markets (09:30-16:00 EST)
- Individual session toggle controls for focused analysis
### 💧 Liquidity Level Detection
- **Buy-Side Liquidity (BSL)**: Identifies stop losses above swing highs where short positions get stopped out
- **Sell-Side Liquidity (SSL)**: Identifies stop losses below swing lows where long positions get stopped out
- Advanced filtering algorithm to identify only significant liquidity zones
- Configurable pivot strength for sensitivity adjustment
### 🎨 Visual Management System
- **Unclaimed Levels**: Active liquidity zones that haven't been hit (default: black lines)
- **Claimed Levels**: Swept liquidity zones showing historical interaction (default: red lines)
- Customizable line styles, colors, and widths for both states
- Dynamic label system showing session origin and level significance
- Real-time line extension and label positioning
### ⚙️ Advanced Configuration
- **Pivot Strength**: Adjust sensitivity (1-20) for liquidity detection
- **Max Levels Per Side**: Control number of tracked levels (1-10) per session
- **Label Offset**: Customize label positioning
- **Style Customization**: Full control over visual appearance
## 📚 Educational Value
### Core Concepts Explained
- **Liquidity Pools**: Areas where stop losses and pending orders cluster
- **Liquidity Sweeps**: When price moves through levels to trigger stops, then reverses
- **Session-Based Analysis**: How different market sessions create distinct liquidity characteristics
- **Institutional Order Flow**: Understanding how large players interact with retail liquidity
### Trading Applications
- Identify high-probability reversal zones after liquidity sweeps
- Understand where stop losses are likely clustered
- Avoid trading into obvious liquidity traps
- Use session context for timing entries and exits
- Recognize institutional accumulation and distribution patterns
### Code Learning Opportunities
- **Pine Script v6 Best Practices**: Modern syntax and efficient coding patterns
- **Object-Oriented Design**: Custom types and methods for clean code organization
- **Array Management**: Dynamic data structure handling for performance
- **Visual Programming**: Line, label, and styling management
- **Session Detection**: Time-based filtering and timezone handling
## 🔧 Technical Implementation
### Performance Optimized
- Efficient memory management with automatic cleanup
- Limited historical level tracking to maintain responsiveness
- Optimized array operations for smooth real-time updates
- Smart filtering to reduce noise and focus on significant levels
### Code Architecture
- **Modular Design**: Clean separation of concerns with dedicated methods
- **Type Safety**: Custom SessionLiquidity type for organized data management
- **Extensible Structure**: Easy to modify and enhance for specific needs
- **Educational Comments**: Comprehensive documentation throughout
## 💡 Usage Guide
### Basic Setup
1. Add indicator to chart
2. Configure session times for your timezone
3. Adjust pivot strength based on timeframe (higher for lower timeframes)
4. Enable/disable sessions based on your trading focus
### Interpretation
- **Unclaimed levels**: Watch for price interaction and potential reversals
- **Claimed levels**: Use as potential support/resistance after sweep
- **External levels**: Beyond session range, higher significance
- **Internal levels**: Within session range, may indicate ranging conditions
### Best Practices
- Use higher timeframes (15m+) for cleaner signals
- Combine with price action analysis for confirmation
- Consider session overlap periods for increased significance
- Monitor multiple sessions for comprehensive market view
## 🎓 Educational Goals
This open-source project aims to:
- Demystify liquidity concepts for retail traders
- Provide practical coding examples in Pine Script v6
- Encourage understanding of institutional trading behavior
- Foster community learning and collaboration
- Bridge the gap between theory and practical application
## 📄 License & Usage
Released under Mozilla Public License 2.0 - free for educational and commercial use with proper attribution.
## 🤝 Contributing
As an open-source educational tool, contributions are welcome! Whether it's bug fixes, feature enhancements, or educational improvements, your input helps the trading community learn and grow.
## ⚠️ Disclaimer
This indicator is for educational purposes only. All trading involves risk, and past performance does not guarantee future results. Always practice proper risk management and never risk more than you can afford to lose.
---
*By studying and using this indicator, traders can develop a deeper understanding of market microstructure and improve their ability to read institutional order flow patterns.*
Session Seed Range (LON / FRA / NY / CME / ASIA + 3 Custom) — v6Session Seed Range → Lines (LON / FRA / NY / CME / ASIA + 3 Custom)
What it does
This tool draws two horizontal levels—the High and Low of a short seed window at each market open (e.g., London 09:00–09:05)—and extends them to the session close (e.g., 17:30). An optional Mid line (average of seed High/Low) can be displayed as well.
Included sessions
• London, Frankfurt, New York, CME, Asia
• Plus 3 fully custom sessions (name, seed window, session end)
Key features
• Seed window → extended lines: Capture the initial opening move and project it across the trading session.
• Timezone dropdown: Choose from common IANA timezones (incl. Europe/Istanbul)—no manual offset math.
• Label language: DE / EN / TR (or Off) for price labels at the right edge.
• Show/Hide Mid line per your preference.
• 3 custom sessions: Add your own schedules with custom names.
• Per-session styling: Colors and widths for High/Low/Mid.
• Lightweight: Works on any timeframe.
________________________________________
Quick start
1. Pick your Timezone in the Inputs.
2. Enable a session (e.g., London) and set its Seed (HHMM–HHMM) and Session End (HHMM).
3. Optionally turn on Show mid line and Labels (DE/EN/TR).
4. Repeat for other sessions or use the Custom A/B/C blocks.
Tip: The seed window must be visible on the chart’s timeframe so the High/Low can be collected. If you don’t see lines, zoom in or use a lower timeframe.
________________________________________
Inputs overview
• Timezone: IANA timezone selection.
• Labels: Off / DE / EN / TR + label offset (ticks).
• Show mid line: Toggle Mid (average of seed High/Low).
• Session blocks (London, Frankfurt, New York, CME, Asia, Custom A/B/C):
o Enable, Seed (HHMM–HHMM), Session End (HHMM)
o High/Low/Mid colors, Width
________________________________________
Notes & limitations
• Lines are built from the seed window only; they do not repaint once the seed completes.
• If the chart timeframe is too high to include the seed window, switch to a lower TF or widen the seed.
• This indicator is for analysis/education only and not financial advice.
________________________________________
Changelog (suggested)
• v1.0.0 — Initial release: LON/FRA/NY/CME/ASIA + 3 Custom, TZ dropdown, labels DE/EN/TR, Mid toggle.
________________________________________
If you want a shorter “store blurb” version, use:
Draws High/Low of a small opening seed window (e.g., London 09:00–09:05) and extends them to session close. Includes London, Frankfurt, New York, CME, Asia + 3 custom sessions. Timezone dropdown (incl. Europe/Istanbul), labels in DE/EN/TR (or Off), optional Mid line, per-session styling. Seed window must be visible on your timeframe. Not financial advice.
Exhaustion Reversal# 📘 Exhaustion Reversal – Quick Start Guide
This tool highlights **reversal zones** where price is stretched too far and likely to snap back.
---
## 1. What to Look For
* **Green Box + Neon BUY Arrow** → Possible Buy Setup
* **Red Box + Neon SELL Arrow** → Possible Sell Setup
* Background color:
* Light **green tint** = Bias is LONG (favor buy setups)
* Light **red tint** = Bias is SHORT (favor sell setups)
---
## 2. How to Take a Trade
**BUY Setup**
1. Wait until you see a **green shaded box** and a **neon BUY arrow**.
2. Confirm the candle closed **green** (bullish).
3. **Entry (EP):** Enter at the closing price of the signal candle (labeled “BUY ENTRY”).
4. **Stop Loss (SL):** Set just under the low of the signal candle (labeled “SL”).
5. **Take Profit (TP):**
* Safer target → the blue **Center Line**.
* Aggressive target → **Band 1**.
**SELL Setup**
1. Wait until you see a **red shaded box** and a **neon SELL arrow**.
2. Confirm the candle closed **red** (bearish).
3. **Entry (EP):** Enter at the closing price of the signal candle (labeled “SELL ENTRY”).
4. **Stop Loss (SL):** Set just above the high of the signal candle (labeled “SL”).
5. **Take Profit (TP):**
* Safer target → the blue **Center Line**.
* Aggressive target → **Band 1**.
---
## 3. Quick Rules to Remember
* ✅ Trade WITH the background bias.
* Green background → focus on BUY setups.
* Red background → focus on SELL setups.
* ❌ Skip weak candles. Look for **strong bodies** (bigger candles).
* ❌ Don’t take every arrow. Wait until price stretched to the **outer Band 2**.
* ✅ Manage risk. Never risk more than **1–2% of your account** on a single trade.
---
## 4. Beginner Flow (step-by-step)
1. Watch for **background tint** (green = buy, red = sell).
2. Wait for price to **touch/pierce Band 2**.
3. Watch for a **reversal candle** (green after red, or red after green).
4. Enter at the “ENTRY” label, place SL and TP at the lines.
5. Let the trade play out – don’t move stops unless you scale out.
---
## 5. Example Trade
* NAS100 on 5m chart:
* Background turns red → bias is SHORT.
* Price spikes above **Upper Band 2**.
* Red reversal candle closes.
* Arrow + label appear → Enter SELL.
* SL at candle high, TP at Center Line.
---
💡 **Pro Tip for New Traders:**
Start by practicing this system in a demo account. Focus on spotting the *cleanest* setups where price clearly stretches to Band 2 and gives a strong reversal candle.
60 신저가 숏_신저가“60-Day New Low Short (New Low)” is a momentum breakdown setup that sells short when price prints a fresh 60-day low, aiming to ride continued weakness after support fails.
Enter on the breakdown close (or next open) with confirmation such as expanding volume, relative weakness vs. a benchmark, and price below the 50/200-day MAs.
Manage risk with a stop above the recent swing high or 20-day high; take profits via ATR-based targets or a trailing stop, and be cautious around earnings/news catalysts.
60 신고가 롱_신고가“60-Day New High Long (New High)” is a momentum breakout setup that buys when price prints a fresh 60-day high, expecting continuation once resistance gives way.
Enter on the breakout close (or next open) with confirmation such as expanding volume, relative strength vs. a benchmark, and price above the 50/200-day MAs.
Manage risk with a stop below the recent swing low or 20-day low; take profits via ATR-based targets or a trailing stop, and be cautious around earnings/news catalysts.
60 신저가 숏_신저가“60-Day New Low Short (New Low)” is a momentum breakdown setup that sells short when price prints a fresh 60-day low, aiming to ride continued weakness after support fails.
Enter on the breakdown close (or next open) with confirmation such as expanding volume, relative weakness vs. a benchmark, and price below the 50/200-day MAs.
Manage risk with a stop above the recent swing high or 20-day high; take profits via ATR-based targets or a trailing stop, and be cautious around earnings/news catalysts.
60 신고가 롱“60-Day New High Long” is a momentum breakout strategy that buys when price makes a fresh 60-day high, expecting continuation after resistance gives way.
Enter on the breakout close (or next open) with confirmation such as expanding volume, relative strength vs. a benchmark, and price above the 50/200-day MAs.
Manage risk with a stop below the recent swing low or 20-day low; take profits via ATR-based targets or a trailing stop, and be cautious around binary catalysts (earnings/news).
60 신저가 숏“60-Day New Low Short” is a momentum breakdown setup that sells short when price prints a fresh 60-day low, betting that failed support will extend the downtrend.
Entries are usually taken on the breakdown close (or next open) with confirmation like rising volume, relative weakness, and price below the 50/200-day MAs.
Manage risk with a stop above the recent swing high or 20-day high; take profits via ATR-based targets or a trailing stop, and avoid trades near major catalysts (earnings/news).
All-in-One Indicator**All-in-One Trading Indicator** 🛠️
This powerful and versatile TradingView indicator combines multiple popular technical tools into a single, easy-to-use script. Designed for traders who want a comprehensive view of the market, it includes:
* **MACD** – with optional lines and histogram for momentum analysis
* **Multiple Moving Averages (MA1/MA2/MA3)** – SMA or EMA, fully customizable
* **RSI** – short or long-term momentum indicator
* **VWAP** – volume-weighted average price for intraday trend spotting
* **Supertrend** – clear trend direction signals
* **ADX & DMI** – trend strength and directional movement
* **Stochastic** – %K and %D lines with overbought/oversold zones
* **Bollinger Bands** – upper and lower bands for volatility analysis
✅ All components are optional and fully configurable
✅ Designed to give a complete market overview in one pane or overlay
✅ Perfect for intraday, swing, and position traders
**Make smarter trading decisions by combining trend, momentum, and volatility insights in one place!**
---
TAPDA Vision by TSINCHRONISE ft Grok This is the newly created TAPDA vision indictor 🔮
This time I used Grok to make the entire thing, It currently is working but I am refining and will be upgrading some features.
For now it can carry out a number of important tasks for TAPDA traders :
-Highlights FVGs that haven't been tapped within customizable size an time parameters
-Highlights OBs that haven't been tapped within customizable size an time parameters
-Has Option to Highlight PD Arrays in for 3 different specific times of day (optional)
-Has a Dynamic Highlight function which will highlight untapped PD arrays which were formed in the current hour you are using the indicator and adjusts every hour automatically
This is a work in progress but is useable - Updates to come.