AMD Strategy [Ahmad Albara]

ahmadalbara64 · strategy · 497 行 · 点赞 58 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
strategy("AMD Strategy (Ahmad Albara)", shorttitle="AMD ", overlay=true, initial_capital=10000,
     default_qty_type=strategy.fixed, default_qty_value=1, pyramiding=0,
     commission_type=strategy.commission.percent, commission_value=0.0, slippage=0,
     margin_long=0, margin_short=0, process_orders_on_close=true, calc_on_every_tick=false,
     max_boxes_count=100, max_lines_count=300, max_labels_count=300)
 
// ═════════════════════════════════════════════════════════════════════════════
// INPUT
// ═════════════════════════════════════════════════════════════════════════════
gAMD = "01 · AMD"
accBars     = input.int(6, "Accumulation lookback", minval=5, maxval=50, group=gAMD)
rangeAtrMax = input.float(2, "Max range / ATR", minval=0.2, step=0.1, group=gAMD)
maxWait     = input.int(6, "Bar tunggu setelah manipulation", minval=1, maxval=50, group=gAMD)
rangeExpiry = input.int(20, "Range kedaluwarsa (bar)", minval=10, maxval=300, group=gAMD)
 
gFilter = "02 · Filter"
minBodyPct   = input.float(35, "Min body breakout (%)", minval=1, maxval=100, group=gFilter)
profileRows  = input.int(24, "Jumlah bin POC", minval=8, maxval=60, group=gFilter)
pocMode      = input.string("Candle tembus POC", "Konfirmasi POC", options=["Candle tembus POC", "Body penuh di sisi POC"], group=gFilter)
useIFVG      = input.bool(false, "Wajib konfirmasi iFVG", group=gFilter)
ifvgLookback = input.int(8, "iFVG lookback", minval=1, maxval=30, group=gFilter)
 
gLevel = "03 · Level SL / TP"
slMode    = input.string("ATR", "Mode SL", options=["Pips", "ATR"], group=gLevel)
slPips    = input.float(30, "SL (pips)", minval=0.1, step=0.1, group=gLevel)
pipSize   = input.float(0.1, "Unit harga per pip", minval=0.000001, step=0.01, group=gLevel)
slAtrMult = input.float(1.4, "SL (x ATR)", minval=0.1, step=0.1, group=gLevel)
rrMode    = input.string("1:1", "Risk : Reward", options=["1:1", "1:1.5", "1:2", "1:2.5", "1:3"], group=gLevel)
 
gBT = "04 · Backtest"
startTime = input.time(timestamp("2026-09-29 00:00 +0000"), "Mulai backtest", group=gBT)
endTime   = input.time(timestamp("2030-12-31 00:00 +0000"), "Akhir backtest", group=gBT)
sizeMode  = input.string("Risk % equity", "Mode ukuran posisi", options=["Risk % equity", "Qty tetap"], group=gBT)
riskPct   = input.float(1.0, "Risk per trade (% equity)", minval=0.01, maxval=100, step=0.1, group=gBT)
fixedQty  = input.float(1.0, "Qty tetap", minval=0.000001, step=0.01, group=gBT)
maxLev    = input.float(20.0, "Batas leverage maksimum (x)", minval=0.1, step=0.5, group=gBT)
onePos    = input.bool(true, "Abaikan sinyal saat posisi masih terbuka", group=gBT)
maxHold   = input.int(0, "Time stop (bar, 0 = nonaktif)", minval=0, maxval=1000, group=gBT)
 
gVisual = "05 · Tampilan"
showZone     = input.bool(false, "Zona accumulation", group=gVisual)
showPOC      = input.bool(false, "Garis POC", group=gVisual)
showSweep    = input.bool(false, "Penanda manipulation", group=gVisual)
showLevels   = input.bool(true, "Level Entry / SL / TP", group=gVisual)
levelBars    = input.int(18, "Panjang level (bar)", minval=2, maxval=100, group=gVisual)
historyCount = input.int(8, "Riwayat setup ditampilkan", minval=1, maxval=40, group=gVisual)
buyCol       = input.color(#26A69A, "Warna BUY", group=gVisual)
sellCol      = input.color(#EF5350, "Warna SELL", group=gVisual)
 
gDash = "06 · Dashboard"
showDash    = input.bool(true, "Panel performa", group=gDash)
dashPos     = input.string("Top right", "Posisi panel", options=["Top right", "Top left", "Bottom right", "Bottom left"], group=gDash)
showMonthly = input.bool(true, "Heatmap return bulanan", group=gDash)
monthlyPos  = input.string("Bottom right", "Posisi heatmap", options=["Top right", "Top left", "Bottom right", "Bottom left", "Bottom center"], group=gDash)
yearsShown  = input.int(4, "Jumlah tahun heatmap", minval=1, maxval=8, group=gDash)
 
// ═════════════════════════════════════════════════════════════════════════════
// PERHITUNGAN DASAR
// ═════════════════════════════════════════════════════════════════════════════
atr         = ta.atr(14)
candleRange = math.max(high - low, syminfo.mintick)
bodyPct     = math.abs(close - open) / candleRange * 100.0
bullBody    = close > open and bodyPct >= minBodyPct
bearBody    = close < open and bodyPct >= minBodyPct
 
rangeHigh  = ta.highest(high[1], accBars)
rangeLow   = ta.lowest(low[1], accBars)
rangeValid = not na(rangeHigh) and not na(atr) and (rangeHigh - rangeLow) <= atr * rangeAtrMax
 
rr = rrMode == "1:1" ? 1.0 : rrMode == "1:1.5" ? 1.5 : rrMode == "1:2" ? 2.0 : rrMode == "1:2.5" ? 2.5 : 3.0
 
// Estimasi POC: volume tiap bar dimasukkan ke bin yang memuat HLC3 (aproksimasi).
f_poc(float hi, float lo, int rows, int n) =>
    float res = na
    float binSize = (hi - lo) / rows
    if binSize > 0
        float[] vols = array.new_float(rows, 0.0)
        for j = 1 to n
            float t = hlc3[j]
            int idx = int(math.floor((t - lo) / binSize))
            idx := math.min(math.max(idx, 0), rows - 1)
            array.set(vols, idx, array.get(vols, idx) + nz(volume[j]))
        float maxV = array.max(vols)
        int best = array.indexof(vols, maxV)
        res := maxV > 0 ? lo + (best + 0.5) * binSize : (hi + lo) / 2.0
    res
 
pocNow = f_poc(rangeHigh, rangeLow, profileRows, accBars)
 
// ═════════════════════════════════════════════════════════════════════════════
// STATE & PENYIMPANAN OBJEK
// ═════════════════════════════════════════════════════════════════════════════
var float accHigh      = na
var float accLow       = na
var float poc          = na
var int   lastRangeBar = na
var int   sweepBar     = na
var int   bias         = 0
var box   zone         = na
var int   lastDir      = 0
var float lastEntry    = na
var float lastSL       = na
var float lastTP       = na
 
var box[]   zoneStore  = array.new_box()
var line[]  lineStore  = array.new_line()
var label[] labelStore = array.new_label()
 
f_trim_boxes(box[] arr, int limit) =>
    while array.size(arr) > limit
        box.delete(array.shift(arr))
    array.size(arr)
 
f_trim_lines(line[] arr, int limit) =>
    while array.size(arr) > limit
        line.delete(array.shift(arr))
    array.size(arr)
 
f_trim_labels(label[] arr, int limit) =>
    while array.size(arr) > limit
        label.delete(array.shift(arr))
    array.size(arr)
 
confirmed = barstate.isconfirmed
bool sweepLowEvt  = false
bool sweepHighEvt = false
 
// ── 1. ACCUMULATION ─────────────────────────────────────────────────────────
newRange = rangeValid and bias == 0 and (na(lastRangeBar) or bar_index - lastRangeBar > accBars)
if confirmed and newRange and not na(pocNow)
    accHigh      := rangeHigh
    accLow       := rangeLow
    poc          := pocNow
    lastRangeBar := bar_index
    zone         := na
    if showZone
        zone := box.new(bar_index - accBars, accHigh, bar_index, accLow,
             bgcolor=color.new(color.gray, 93), border_color=color.new(color.gray, 75), border_width=1)
        array.push(zoneStore, zone)
        f_trim_boxes(zoneStore, historyCount)
 
// ── 2. MANIPULATION ─────────────────────────────────────────────────────────
if confirmed and bias == 0 and not na(accHigh)
    if low < accLow and close > accLow
        bias         := 1
        sweepBar     := bar_index
        sweepLowEvt  := true
    else if high > accHigh and close < accHigh
        bias         := -1
        sweepBar     := bar_index
        sweepHighEvt := true
 
if not na(accHigh) and not na(zone)
    box.set_right(zone, bar_index)
 
// ═════════════════════════════════════════════════════════════════════════════
// iFVG (opsional)
// ═════════════════════════════════════════════════════════════════════════════
bearFvg = not na(low[2]) and low[2] > high
bullFvg = not na(high[2]) and low > high[2]
var float lastBearGapTop    = na
var int   lastBearGapBar    = na
var float lastBullGapBottom = na
var int   lastBullGapBar    = na
 
if confirmed
    if bearFvg
        lastBearGapTop := low[2]
        lastBearGapBar := bar_index
    if bullFvg
        lastBullGapBottom := high[2]
        lastBullGapBar    := bar_index
 
bullIFVG = not na(lastBearGapTop) and close > lastBearGapTop and close[1] <= lastBearGapTop and bar_index - lastBearGapBar <= ifvgLookback
bearIFVG = not na(lastBullGapBottom) and close < lastBullGapBottom and close[1] >= lastBullGapBottom and bar_index - lastBullGapBar <= ifvgLookback
longIFVGok  = not useIFVG or bullIFVG
shortIFVGok = not useIFVG or bearIFVG
 
// ═════════════════════════════════════════════════════════════════════════════
// 3. DISTRIBUTION: sinyal
// ═════════════════════════════════════════════════════════════════════════════
inWindow = bias != 0 and not na(sweepBar) and bar_index > sweepBar and bar_index - sweepBar <= maxWait
 
fullBody   = pocMode == "Body penuh di sisi POC"
longPocOk  = not na(poc) and close > poc and (not fullBody or open > poc)
shortPocOk = not na(poc) and close < poc and (not fullBody or open < poc)
 
longSignal  = confirmed and inWindow and bias == 1  and longPocOk  and bullBody and longIFVGok
shortSignal = confirmed and inWindow and bias == -1 and shortPocOk and bearBody and shortIFVGok
 
float slDist = slMode == "Pips" ? slPips * pipSize : atr * slAtrMult
float tpDist = slDist * rr
 
// ═════════════════════════════════════════════════════════════════════════════
// EKSEKUSI STRATEGY
// ═════════════════════════════════════════════════════════════════════════════
inRange  = time >= startTime and time <= endTime
canEnter = inRange and (not onePos or strategy.position_size == 0)
 
float qtyRaw = sizeMode == "Risk % equity" ? strategy.equity * riskPct / 100.0 / (slDist * syminfo.pointvalue) : fixedQty
float qtyCap = strategy.equity * maxLev / (close * syminfo.pointvalue)
float qtyUse = math.max(math.min(qtyRaw, qtyCap), 0.0)
bool  qtyOk  = qtyUse > 0 and not na(qtyUse)
 
takeLong  = longSignal  and canEnter and qtyOk
takeShort = shortSignal and canEnter and qtyOk
 
var float[] riskList = array.new_float()
 
f_draw_signal(bool isLong, float entry, float sl, float tp) =>
    color dirCol = isLong ? buyCol : sellCol
    array.push(labelStore, label.new(bar_index, isLong ? low : high, isLong ? "BUY" : "SELL",
         style=isLong ? label.style_label_up : label.style_label_down,
         color=dirCol, textcolor=color.white, size=size.tiny))
    if showLevels
        int x2 = bar_index + levelBars
        array.push(lineStore, line.new(bar_index, entry, x2, entry, color=color.new(color.gray, 30), style=line.style_dotted, width=1))
        array.push(lineStore, line.new(bar_index, sl, x2, sl, color=color.new(sellCol, 15), width=1))
        array.push(lineStore, line.new(bar_index, tp, x2, tp, color=color.new(buyCol, 15), width=1))
        array.push(labelStore, label.new(x2, sl, "SL", style=label.style_none, textcolor=sellCol, size=size.tiny))
        array.push(labelStore, label.new(x2, tp, "TP", style=label.style_none, textcolor=buyCol, size=size.tiny))
    f_trim_lines(lineStore, historyCount * 3)
    f_trim_labels(labelStore, showLevels ? historyCount * 3 : historyCount)
 
if takeLong
    lastDir   := 1
    lastEntry := close
    lastSL    := close - slDist
    lastTP    := close + tpDist
    array.push(riskList, qtyUse * slDist * syminfo.pointvalue)
    strategy.entry("L", strategy.long, qty=qtyUse)
    strategy.exit("XL", "L", stop=lastSL, limit=lastTP)
    f_draw_signal(true, lastEntry, lastSL, lastTP)
 
if takeShort
    lastDir   := -1
    lastEntry := close
    lastSL    := close + slDist
    lastTP    := close - tpDist
    array.push(riskList, qtyUse * slDist * syminfo.pointvalue)
    strategy.entry("S", strategy.short, qty=qtyUse)
    strategy.exit("XS", "S", stop=lastSL, limit=lastTP)
    f_draw_signal(false, lastEntry, lastSL, lastTP)
 
if strategy.position_size > 0
    strategy.exit("XL", "L", stop=lastSL, limit=lastTP)
if strategy.position_size < 0
    strategy.exit("XS", "S", stop=lastSL, limit=lastTP)
 
if maxHold > 0 and strategy.opentrades > 0
    if bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades - 1) >= maxHold
        strategy.close_all(comment="Time stop")
 
// ═════════════════════════════════════════════════════════════════════════════
// RESET SETUP
// ═════════════════════════════════════════════════════════════════════════════
float pocPlot = showPOC and not na(accHigh) ? poc : na
 
waitExpired = bias != 0 and not na(sweepBar) and bar_index - sweepBar > maxWait
rangeStale  = bias == 0 and not na(accHigh) and not na(lastRangeBar) and bar_index - lastRangeBar > rangeExpiry
resetSetup  = confirmed and (longSignal or shortSignal or waitExpired or rangeStale)
 
if resetSetup
    bias     := 0
    sweepBar := na
    accHigh  := na
    accLow   := na
    poc      := na
    zone     := na
 
// ═════════════════════════════════════════════════════════════════════════════
// STATISTIK BACKTEST (diakumulasi per trade yang baru tertutup)
// ═════════════════════════════════════════════════════════════════════════════
var int   baseYear   = year
var int   prevClosed = 0
var int   longN = 0
var int   longW = 0
var int   shortN = 0
var int   shortW = 0
var float longPnl = 0.0
var float shortPnl = 0.0
var int   curW = 0
var int   curL = 0
var int   maxW = 0
var int   maxL = 0
var float sumR = 0.0
var float sumR2 = 0.0
var int   nR = 0
var float sumBars = 0.0
var float bestTrade = 0.0
var float worstTrade = 0.0
var float peakEq = strategy.initial_capital
var float maxDDpct = 0.0
var float maxDDcash = 0.0
var float[] monthPnl = array.new_float(12 * 40, 0.0)
 
float eqNow = strategy.equity
peakEq := math.max(peakEq, eqNow)
float ddCash = peakEq - eqNow
float ddPct  = peakEq > 0 ? ddCash / peakEq * 100.0 : 0.0
maxDDcash := math.max(maxDDcash, ddCash)
maxDDpct  := math.max(maxDDpct, ddPct)
 
if strategy.closedtrades > prevClosed
    for i = prevClosed to strategy.closedtrades - 1
        float p = strategy.closedtrades.profit(i)
        bool isL = strategy.closedtrades.size(i) > 0
        int nBars = strategy.closedtrades.exit_bar_index(i) - strategy.closedtrades.entry_bar_index(i)
        float risk = i < array.size(riskList) ? array.get(riskList, i) : na
        float rMult = not na(risk) and risk > 0 ? p / risk : na
 
        if isL
            longN += 1
            longPnl += p
            if p > 0
                longW += 1
        else
            shortN += 1
            shortPnl += p
            if p > 0
                shortW += 1
 
        if p > 0
            curW += 1
            curL := 0
        else if p < 0
            curL += 1
            curW := 0
        maxW := math.max(maxW, curW)
        maxL := math.max(maxL, curL)
 
        if not na(rMult)
            sumR += rMult
            sumR2 += rMult * rMult
            nR += 1
        sumBars += nBars
        bestTrade := math.max(bestTrade, p)
        worstTrade := math.min(worstTrade, p)
 
        int et = strategy.closedtrades.exit_time(i)
        int ix = (year(et) - baseYear) * 12 + (month(et) - 1)
        if ix >= 0 and ix < array.size(monthPnl)
            array.set(monthPnl, ix, array.get(monthPnl, ix) + p)
    prevClosed := strategy.closedtrades
 
// ═════════════════════════════════════════════════════════════════════════════
// PLOT & ALERT
// ═════════════════════════════════════════════════════════════════════════════
plot(pocPlot, "POC", color=color.new(color.yellow, 25), linewidth=1, style=plot.style_linebr)
plotshape(showSweep and sweepLowEvt, "Manipulation ↓", style=shape.circle, location=location.belowbar,
     color=color.new(buyCol, 45), size=size.tiny)
plotshape(showSweep and sweepHighEvt, "Manipulation ↑", style=shape.circle, location=location.abovebar,
     color=color.new(sellCol, 45), size=size.tiny)
 
alertcondition(takeLong,  title="AMD BUY",  message="AMD BUY: sweep bawah range lalu body bullish close di atas POC.")
alertcondition(takeShort, title="AMD SELL", message="AMD SELL: sweep atas range lalu body bearish close di bawah POC.")
 
// ═════════════════════════════════════════════════════════════════════════════
// DASHBOARD PERFORMA
// ═════════════════════════════════════════════════════════════════════════════
f_pos(string p) =>
    p == "Top left" ? position.top_left : p == "Bottom right" ? position.bottom_right : p == "Bottom left" ? position.bottom_left : p == "Bottom center" ? position.bottom_center : position.top_right
 
f_num(float x, string fmt) =>
    na(x) ? "—" : str.tostring(x, fmt)
 
f_sgn(float x, string fmt) =>
    na(x) ? "—" : (x > 0 ? "+" : "") + str.tostring(x, fmt)
 
muted   = color.new(chart.fg_color, 40)
neutral = chart.fg_color
hdrBg   = color.new(chart.fg_color, 90)
warnCol = #FFB300
 
var table dash = showDash ? table.new(f_pos(dashPos), 4, 12, bgcolor=color.new(chart.bg_color, 6),
     frame_color=color.new(chart.fg_color, 80), frame_width=1, border_color=color.new(chart.fg_color, 92), border_width=1) : na
 
f_row(int r, string k1, string v1, color c1, string k2, string v2, color c2) =>
    table.cell(dash, 0, r, k1, text_color=muted, text_size=size.small, text_halign=text.align_left)
    table.cell(dash, 1, r, v1, text_color=c1, text_size=size.small, text_halign=text.align_right)
    table.cell(dash, 2, r, k2, text_color=muted, text_size=size.small, text_halign=text.align_left)
    table.cell(dash, 3, r, v2, text_color=c2, text_size=size.small, text_halign=text.align_right)
 
if showDash and barstate.islast
    int   n       = strategy.closedtrades
    int   wins    = strategy.wintrades
    int   losses  = strategy.losstrades
    float gp      = strategy.grossprofit
    float gl      = strategy.grossloss
    float netP    = strategy.netprofit
    float retPct  = netP / strategy.initial_capital * 100.0
    float winRate = n > 0 ? wins / float(n) * 100.0 : na
    float pf      = gl > 0 ? gp / gl : na
    float avgWin  = wins > 0 ? gp / wins : na
    float avgLoss = losses > 0 ? gl / losses : na
    float payoff  = not na(avgWin) and not na(avgLoss) and avgLoss > 0 ? avgWin / avgLoss : na
    float expR    = nR > 0 ? sumR / nR : na
    float meanR   = nR > 0 ? sumR / nR : na
    float varR    = nR > 1 ? sumR2 / nR - meanR * meanR : na
    float sdR     = not na(varR) ? math.sqrt(math.max(varR, 0.0)) : na
    float sqn     = not na(sdR) and sdR > 0 ? math.sqrt(nR) * meanR / sdR : na
    float recov   = maxDDcash > 0 ? netP / maxDDcash : na
    float avgBars = n > 0 ? sumBars / n : na
 
    color cNet = netP > 0 ? buyCol : netP < 0 ? sellCol : neutral
    color cPF  = na(pf) ? (gp > 0 ? buyCol : neutral) : pf >= 1.5 ? buyCol : pf >= 1.0 ? neutral : sellCol
    color cWR  = na(winRate) ? neutral : winRate >= 50 ? buyCol : neutral
    color cExp = na(expR) ? neutral : expR > 0 ? buyCol : sellCol
    color cSqn = na(sqn) ? neutral : sqn >= 2.0 ? buyCol : sqn >= 1.0 ? neutral : sellCol
    color cDD  = maxDDpct >= 25 ? sellCol : maxDDpct >= 15 ? warnCol : neutral
    color cRec = na(recov) ? neutral : recov >= 2 ? buyCol : recov >= 1 ? neutral : sellCol
 
    // Judul
    table.cell(dash, 0, 0, "AMD · BACKTEST   " + syminfo.ticker + " · " + timeframe.period + "   " +
         str.format_time(startTime, "yyyy-MM-dd", syminfo.timezone) + " → " + str.format_time(math.min(endTime, time), "yyyy-MM-dd", syminfo.timezone),
         text_color=neutral, text_size=size.small, text_halign=text.align_left, bgcolor=hdrBg)
    table.merge_cells(dash, 0, 0, 3, 0)
 
    // Header seksi
    table.cell(dash, 0, 1, "KINERJA", text_color=muted, text_size=size.tiny, text_halign=text.align_left)
    table.cell(dash, 1, 1, "", text_size=size.tiny)
    table.cell(dash, 2, 1, "STATISTIK TRADE", text_color=muted, text_size=size.tiny, text_halign=text.align_left)
    table.cell(dash, 3, 1, "", text_size=size.tiny)
 
    f_row(2, "Net profit",     f_sgn(netP, "#.##"),                       cNet, "Total trade",    str.tostring(n),                         neutral)
    f_row(3, "Return",         f_sgn(retPct, "#.##") + "%",               cNet, "Win rate",       f_num(winRate, "#.#") + "%",             cWR)
    f_row(4, "Profit factor",  na(pf) ? (gp > 0 ? "∞" : "—") : str.tostring(pf, "#.##"), cPF, "Payoff (avg W/L)", f_num(payoff, "#.##"),  na(payoff) ? neutral : payoff >= 1 ? buyCol : neutral)
    f_row(5, "Max drawdown",   str.tostring(maxDDpct, "#.##") + "%",      cDD,  "Expectancy (R)", f_sgn(expR, "#.##"),                     cExp)
    f_row(6, "Recovery factor", f_num(recov, "#.##"),                     cRec, "SQN",            f_num(sqn, "#.##"),                      cSqn)
    f_row(7, "Gross profit / loss", f_num(gp, "#.##") + " / " + f_num(gl, "#.##"), neutral, "Best / worst", f_sgn(bestTrade, "#.##") + " / " + f_sgn(worstTrade, "#.##"), neutral)
    f_row(8, "Equity akhir",   str.tostring(strategy.equity, "#.##"),     neutral, "Streak W / L (maks)", str.tostring(maxW) + " / " + str.tostring(maxL), maxL >= 8 ? sellCol : neutral)
 
    // Long vs Short
    table.cell(dash, 0, 9, "LONG", text_color=buyCol, text_size=size.tiny, text_halign=text.align_left)
    table.cell(dash, 1, 9, "", text_size=size.tiny)
    table.cell(dash, 2, 9, "SHORT", text_color=sellCol, text_size=size.tiny, text_halign=text.align_left)
    table.cell(dash, 3, 9, "", text_size=size.tiny)
    string lTxt = str.tostring(longN) + " trade · " + (longN > 0 ? str.tostring(longW / float(longN) * 100.0, "#") : "—") + "% · " + f_sgn(longPnl, "#.##")
    string sTxt = str.tostring(shortN) + " trade · " + (shortN > 0 ? str.tostring(shortW / float(shortN) * 100.0, "#") : "—") + "% · " + f_sgn(shortPnl, "#.##")
    table.cell(dash, 0, 10, "Trade · WR · P/L", text_color=muted, text_size=size.small, text_halign=text.align_left)
    table.cell(dash, 1, 10, lTxt, text_color=longPnl >= 0 ? buyCol : sellCol, text_size=size.small, text_halign=text.align_right)
    table.cell(dash, 2, 10, "Trade · WR · P/L", text_color=muted, text_size=size.small, text_halign=text.align_left)
    table.cell(dash, 3, 10, sTxt, text_color=shortPnl >= 0 ? buyCol : sellCol, text_size=size.small, text_halign=text.align_right)
 
    // Penilaian
    string verdict = n < 30 ? "SAMPEL KECIL (" + str.tostring(n) + " trade, minimal 30)" :
         (not na(pf) and pf >= 1.5 and not na(sqn) and sqn >= 2.0 and netP > 0) ? "KUAT · edge terlihat konsisten" :
         (not na(pf) and pf >= 1.2 and netP > 0) ? "LAYAK · uji lanjut (out-of-sample)" :
         (netP > 0) ? "MARGINAL · edge tipis" : "TIDAK PROFITABEL"
    color verdictCol = n < 30 ? warnCol : (not na(pf) and pf >= 1.5 and not na(sqn) and sqn >= 2.0 and netP > 0) ? buyCol :
         (not na(pf) and pf >= 1.2 and netP > 0) ? buyCol : (netP > 0) ? warnCol : sellCol
    table.cell(dash, 0, 11, "Penilaian: " + verdict + "   ·   Rata-rata " + f_num(avgBars, "#.#") + " bar/trade",
         text_color=verdictCol, text_size=size.small, text_halign=text.align_left, bgcolor=hdrBg)
    table.merge_cells(dash, 0, 11, 3, 11)
 
// ═════════════════════════════════════════════════════════════════════════════
// HEATMAP RETURN BULANAN (% dari modal awal)
// ═════════════════════════════════════════════════════════════════════════════
var table mt = showMonthly ? table.new(f_pos(monthlyPos), 14, yearsShown + 1, bgcolor=color.new(chart.bg_color, 6),
     frame_color=color.new(chart.fg_color, 80), frame_width=1, border_color=color.new(chart.fg_color, 92), border_width=1) : na
var string[] monthNames = array.from("Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des")
 
f_heat(float v, float mx) =>
    float k = mx > 0 ? math.min(math.abs(v) / mx, 1.0) : 0.0
    color base = v > 0 ? buyCol : sellCol
    v == 0 ? color.new(chart.fg_color, 100) : color.new(base, int(85 - k * 60))
 
if showMonthly and barstate.islast
    int lastY  = year(time)
    int startY = math.max(baseYear, lastY - yearsShown + 1)
    float mx = 0.0
    for y = startY to lastY
        for m = 0 to 11
            int ix0 = (y - baseYear) * 12 + m
            if ix0 >= 0 and ix0 < array.size(monthPnl)
                mx := math.max(mx, math.abs(array.get(monthPnl, ix0)) / strategy.initial_capital * 100.0)
 
    table.cell(mt, 0, 0, "Tahun", text_color=muted, text_size=size.tiny, bgcolor=hdrBg)
    for m = 0 to 11
        table.cell(mt, m + 1, 0, array.get(monthNames, m), text_color=muted, text_size=size.tiny, bgcolor=hdrBg)
    table.cell(mt, 13, 0, "Total", text_color=muted, text_size=size.tiny, bgcolor=hdrBg)
 
    for r = 1 to yearsShown
        int y = startY + r - 1
        if y <= lastY
            float tot = 0.0
            table.cell(mt, 0, r, str.tostring(y), text_color=neutral, text_size=size.tiny, bgcolor=hdrBg)
            for m = 0 to 11
                int ix = (y - baseYear) * 12 + m
                float v = ix >= 0 and ix < array.size(monthPnl) ? array.get(monthPnl, ix) / strategy.initial_capital * 100.0 : 0.0
                tot += v
                table.cell(mt, m + 1, r, v == 0 ? "·" : str.tostring(v, "#.#"), text_color=v == 0 ? muted : neutral, text_size=size.tiny, bgcolor=f_heat(v, mx))
            table.cell(mt, 13, r, f_sgn(tot, "#.#") + "%", text_color=tot >= 0 ? buyCol : sellCol, text_size=size.tiny, bgcolor=hdrBg)
        else
            for c = 0 to 13
                table.cell(mt, c, r, "", text_size=size.tiny)

← 返回列表