本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Talenta Samurai | Proprietary Indicator Suite", shorttitle="Talenta Samurai", overlay=true, max_labels_count=500, max_lines_count=500, max_boxes_count=300)
// TALENTA SAMURAI | Proprietary Talenta indicator suite
// The design translates the ebook's eight consistency pillars into automatic,
// chart-based proxies, with optional manual score adjustment.
// DISCLAIMER: Educational and analytical software only. It is not investment advice,
// does not guarantee results, and does not place orders. Trading involves substantial risk.
// ─────────────────────────────────────────────────────────────────────────────
// 1. INPUTS
// ─────────────────────────────────────────────────────────────────────────────
groupSignal = "01 · Signal and confluence"
fastLen = input.int(21, "Fast EMA", minval=2, group=groupSignal)
slowLen = input.int(89, "Slow EMA", minval=3, group=groupSignal)
contextTf = input.timeframe("240", "Higher-timeframe context", group=groupSignal)
useHtf = input.bool(true, "Use higher-timeframe trend", group=groupSignal)
minScore = input.int(7, "Minimum confluence score (out of 9)", minval=2, maxval=9, group=groupSignal)
allowLong = input.bool(true, "Enable long signals", group=groupSignal)
allowShort = input.bool(true, "Enable short signals", group=groupSignal)
confirmedOnly = input.bool(true, "Confirm signals at bar close", group=groupSignal)
candleMode = input.string("Add confluence", "Candle/VSA confirmation", options=["Off", "Add confluence", "Require confirmation"], group=groupSignal)
showCandleMarkers = input.bool(false, "Show candle/VSA markers", group=groupSignal)
groupRisk = "02 · Risk and volatility"
atrLen = input.int(17, "ATR length", minval=2, group=groupRisk)
stopAtr = input.float(1.8, "Initial stop (ATR multiple)", minval=0.2, step=0.1, group=groupRisk)
tp1R = input.float(1.0, "Target 1 (R)", minval=0.2, step=0.1, group=groupRisk)
tp2R = input.float(2.0, "Target 2 (R)", minval=0.3, step=0.1, group=groupRisk)
tp3R = input.float(3.0, "Target 3 (R)", minval=0.5, step=0.1, group=groupRisk)
trailAtr = input.float(1.5, "Trailing stop after Target 1 (ATR)", minval=0.2, step=0.1, group=groupRisk)
accountEquity = input.float(10000, "Reference account equity", minval=0, group=groupRisk)
riskPct = input.float(0.5, "Estimated risk per trade (%)", minval=0.05, maxval=5, step=0.05, group=groupRisk)
maxTradesDay = input.int(2, "Maximum new trades per day", minval=1, maxval=50, group=groupRisk)
maxDailyLossR = input.float(2.0, "Daily loss limit (R)", minval=0.5, step=0.25, group=groupRisk)
maxAtrPct = input.float(15.0, "Maximum ATR as % of price", minval=0.1, maxval=100, step=0.5, group=groupRisk)
volatilityLookback = input.int(100, "Volatility percentile lookback", minval=20, maxval=500, group=groupRisk)
maxVolatilityPercentile = input.float(97.0, "Block above volatility percentile", minval=50, maxval=100, step=1, group=groupRisk)
groupContext = "03 · Automatic market context"
equityBenchmark = input.symbol("AMEX:SPY", "Equity/index benchmark", group=groupContext)
cryptoBenchmark = input.symbol("COINBASE:BTCUSD", "Crypto benchmark", group=groupContext)
vixSymbol = input.symbol("CBOE:VIX", "Volatility index symbol", group=groupContext)
dxySymbol = input.symbol("TVC:DXY", "US Dollar Index symbol", group=groupContext)
useCrossMarket = input.bool(true, "Use cross-market context", group=groupContext)
manualScoreAdjust = input.int(0, "Optional manual score adjustment (-2 to +2)", minval=-2, maxval=2, group=groupContext)
groupValue = "04 · Price and value"
valueLen = input.int(20, "Fallback value EMA length", minval=2, group=groupValue)
useVwap = input.bool(true, "Use VWAP when available", group=groupValue)
groupLiquidity = "05 · Liquidity, supply and demand"
showLiquidity = input.bool(true, "Show liquidity lines and zones", group=groupLiquidity)
liquidityPivotLen = input.int(5, "Swing pivot strength", minval=2, maxval=30, group=groupLiquidity)
liquidityLineLength = input.int(120, "Projected line/zone length (bars)", minval=10, maxval=500, group=groupLiquidity)
maxLiquidityZones = input.int(5, "Maximum zones per side", minval=1, maxval=20, group=groupLiquidity)
zoneAtrThickness = input.float(0.35, "Supply/demand zone thickness (ATR)", minval=0.05, maxval=3, step=0.05, group=groupLiquidity)
liquidityLineTransparency = input.int(30, "Liquidity line transparency", minval=0, maxval=100, group=groupLiquidity)
liquidityLineWidth = input.int(1, "Liquidity line width", minval=1, maxval=4, group=groupLiquidity)
liquidityBoxTransparency = input.int(84, "Supply/demand box transparency", minval=0, maxval=100, group=groupLiquidity)
liquidityLabelSizeInput = input.string("Tiny", "Liquidity label size", options=["Auto", "Tiny", "Small", "Normal"], group=groupLiquidity)
groupStyle = "06 · Design and display"
designTheme = input.string("Samurai", "Visual design", options=["Samurai", "Explosion", "Cyber", "Future"], group=groupStyle)
showEMAs = input.bool(true, "Show trend EMAs", group=groupStyle)
showValue = input.bool(true, "Show value reference", group=groupStyle)
showRiskLevels = input.bool(true, "Show active stop and targets", group=groupStyle)
showPanel = input.bool(false, "Show information panel", group=groupStyle)
// ─────────────────────────────────────────────────────────────────────────────
// 2. VISUAL THEME
// ─────────────────────────────────────────────────────────────────────────────
buyColor = designTheme == "Explosion" ? color.rgb(177, 255, 0) : designTheme == "Cyber" ? color.rgb(0, 240, 255) : designTheme == "Future" ? color.rgb(71, 130, 255) : color.rgb(226, 177, 72)
sellColor = designTheme == "Explosion" ? color.rgb(255, 74, 0) : designTheme == "Cyber" ? color.rgb(255, 45, 170) : designTheme == "Future" ? color.rgb(255, 75, 120) : color.rgb(210, 54, 68)
trendColor = designTheme == "Explosion" ? color.rgb(255, 215, 0) : designTheme == "Cyber" ? color.rgb(166, 88, 255) : designTheme == "Future" ? color.rgb(0, 220, 170) : color.rgb(95, 154, 226)
valueColor = designTheme == "Cyber" ? color.rgb(255, 100, 220) : designTheme == "Future" ? color.rgb(125, 200, 255) : color.rgb(180, 140, 220)
liqLabelSize = liquidityLabelSizeInput == "Tiny" ? size.tiny : liquidityLabelSizeInput == "Auto" ? size.auto : size.small
// ─────────────────────────────────────────────────────────────────────────────
// 3. PRICE, TREND, VSA AND AUTOMATIC CONTEXT
// ─────────────────────────────────────────────────────────────────────────────
emaFast = ta.ema(close, fastLen)
emaSlow = ta.ema(close, slowLen)
atr = ta.atr(atrLen)
rsi = ta.rsi(close, 14)
volAvg = ta.sma(volume, 20)
volRatio = volAvg > 0 ? volume / volAvg : 1.0
spread = high - low
avgSpread = ta.sma(spread, 20)
body = math.abs(close - open)
barRange = math.max(spread, syminfo.mintick)
closePosition = (close - low) / barRange
upperWick = high - math.max(open, close)
lowerWick = math.min(open, close) - low
bodyHigh = math.max(open, close)
bodyLow = math.min(open, close)
vwapValue = ta.vwap(hlc3)
valueRef = useVwap and not na(vwapValue) ? vwapValue : ta.ema(hlc3, valueLen)
htfFast = request.security(syminfo.tickerid, contextTf, ta.ema(close, fastLen)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
htfSlow = request.security(syminfo.tickerid, contextTf, ta.ema(close, slowLen)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
htfBull = htfFast > htfSlow
htfBear = htfFast < htfSlow
// Candle patterns: hammer, shooting star, engulfing, harami, doji and inside-bar breakout.
isDoji = body <= barRange * 0.10
bullHammer = lowerWick >= math.max(body * 2.0, syminfo.mintick) and upperWick <= barRange * 0.30 and closePosition >= 0.60
bearShootingStar = upperWick >= math.max(body * 2.0, syminfo.mintick) and lowerWick <= barRange * 0.30 and closePosition <= 0.40
bullEngulfing = close > open and close[1] < open[1] and open <= close[1] and close >= open[1]
bearEngulfing = close < open and close[1] > open[1] and open >= close[1] and close <= open[1]
bullHarami = close[1] < open[1] and close > open and bodyHigh < math.max(open[1], close[1]) and bodyLow > math.min(open[1], close[1])
bearHarami = close[1] > open[1] and close < open and bodyHigh < math.max(open[1], close[1]) and bodyLow > math.min(open[1], close[1])
insideBarBullBreak = high[1] < high[2] and low[1] > low[2] and close > high[1]
insideBarBearBreak = high[1] < high[2] and low[1] > low[2] and close < low[1]
bullDojiReversal = isDoji and closePosition >= 0.70 and close > close[1]
bearDojiReversal = isDoji and closePosition <= 0.30 and close < close[1]
// VSA proxies: relative volume, spread and close location. These are not true bid/ask delta.
vsaDemand = volRatio >= 1.20 and not na(avgSpread) and spread <= avgSpread * 0.85 and closePosition >= 0.65 and close >= open
vsaSupply = volRatio >= 1.20 and not na(avgSpread) and spread <= avgSpread * 0.85 and closePosition <= 0.35 and close <= open
bullCandleConfirm = bullHammer or bullEngulfing or bullHarami or insideBarBullBreak or bullDojiReversal or vsaDemand
bearCandleConfirm = bearShootingStar or bearEngulfing or bearHarami or insideBarBearBreak or bearDojiReversal or vsaSupply
candleLongAllowed = candleMode != "Require confirmation" or bullCandleConfirm
candleShortAllowed = candleMode != "Require confirmation" or bearCandleConfirm
candleLongBonus = candleMode != "Off" and bullCandleConfirm ? 1 : 0
candleShortBonus = candleMode != "Off" and bearCandleConfirm ? 1 : 0
candleStatus = bullCandleConfirm and bearCandleConfirm ? "Mixed candle/VSA" : bullCandleConfirm ? "Bullish candle/VSA" : bearCandleConfirm ? "Bearish candle/VSA" : "No candle confirmation"
// Automatic cross-market context uses closed higher-timeframe data and neutral fallback when unavailable.
benchmarkSymbol = syminfo.type == "crypto" ? cryptoBenchmark : equityBenchmark
benchmarkFast = request.security(benchmarkSymbol, contextTf, ta.ema(close, fastLen)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, ignore_invalid_symbol=true)
benchmarkSlow = request.security(benchmarkSymbol, contextTf, ta.ema(close, slowLen)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, ignore_invalid_symbol=true)
vixFast = request.security(vixSymbol, contextTf, ta.ema(close, fastLen)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, ignore_invalid_symbol=true)
vixSlow = request.security(vixSymbol, contextTf, ta.ema(close, slowLen)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, ignore_invalid_symbol=true)
dxyFast = request.security(dxySymbol, contextTf, ta.ema(close, fastLen)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, ignore_invalid_symbol=true)
dxySlow = request.security(dxySymbol, contextTf, ta.ema(close, slowLen)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, ignore_invalid_symbol=true)
benchmarkAvailable = not na(benchmarkFast) and not na(benchmarkSlow)
vixAvailable = not na(vixFast) and not na(vixSlow)
dxyAvailable = not na(dxyFast) and not na(dxySlow)
benchmarkBull = benchmarkAvailable and benchmarkFast > benchmarkSlow
benchmarkBear = benchmarkAvailable and benchmarkFast < benchmarkSlow
vixRising = vixAvailable and vixFast > vixSlow
dxyRising = dxyAvailable and dxyFast > dxySlow
bool autoContextLong = true
bool autoContextShort = true
bool contextAvailable = false
if useCrossMarket and (syminfo.type == "stock" or syminfo.type == "index" or syminfo.type == "crypto") and benchmarkAvailable
contextAvailable := true
bool riskOff = vixRising or dxyRising
autoContextLong := benchmarkBull and not riskOff
autoContextShort := benchmarkBear or riskOff
else if useCrossMarket and syminfo.type == "forex" and dxyAvailable
if syminfo.basecurrency == "USD"
contextAvailable := true
autoContextLong := dxyFast > dxySlow
autoContextShort := dxyFast < dxySlow
else if syminfo.currency == "USD"
contextAvailable := true
autoContextLong := dxyFast < dxySlow
autoContextShort := dxyFast > dxySlow
contextText = not useCrossMarket ? "Disabled" : not contextAvailable ? "Unavailable · neutral" : autoContextLong and not autoContextShort ? "Bullish context" : autoContextShort and not autoContextLong ? "Bearish context" : "Mixed / neutral"
// TradingView company fundamentals are used when the chart symbol supplies quarterly data.
revenueFQ = request.financial(syminfo.tickerid, "TOTAL_REVENUE", "FQ", gaps=barmerge.gaps_off, ignore_invalid_symbol=true)
operatingIncomeFQ = request.financial(syminfo.tickerid, "OPER_INCOME", "FQ", gaps=barmerge.gaps_off, ignore_invalid_symbol=true)
revenueChange = ta.change(revenueFQ)
newRevenueReport = not na(revenueChange) and revenueChange != 0
priorYearRevenue = ta.valuewhen(newRevenueReport, revenueFQ, 4)
fundamentalsAvailable = syminfo.type == "stock" and not na(revenueFQ) and not na(priorYearRevenue) and not na(operatingIncomeFQ)
fundamentalBull = fundamentalsAvailable and revenueFQ > priorYearRevenue and operatingIncomeFQ > 0
fundamentalBear = fundamentalsAvailable and (revenueFQ < priorYearRevenue or operatingIncomeFQ < 0)
fundLong = not fundamentalsAvailable or fundamentalBull
fundShort = not fundamentalsAvailable or fundamentalBear
fundamentalText = not fundamentalsAvailable ? "Unavailable · neutral" : fundamentalBull ? "Revenue growth / positive operating income" : fundamentalBear ? "Revenue or operating-income caution" : "Mixed fundamentals"
// Eight ebook pillars as observable proxies plus a candle/VSA confirmation point.
qualLong = (rsi > 50 and rsi < 75) or (close > open and close > close[1])
qualShort = (rsi < 50 and rsi > 25) or (close < open and close < close[1])
crossUp = ta.crossover(emaFast, emaSlow)
crossDown = ta.crossunder(emaFast, emaSlow)
quantLong = crossUp or (emaFast > emaSlow and close > emaFast and rsi > 52)
quantShort = crossDown or (emaFast < emaSlow and close < emaFast and rsi < 48)
strategyLong = close > emaSlow and (not useHtf or htfBull)
strategyShort = close < emaSlow and (not useHtf or htfBear)
valueLong = close >= valueRef and (atr == 0 or close - valueRef < atr * 2.5)
valueShort = close <= valueRef and (atr == 0 or valueRef - close < atr * 2.5)
volumePressure = ta.ema(volume * (2.0 * close - high - low) / barRange, 10)
flowLong = na(volumePressure) ? close > close[1] : volumePressure > 0 and volRatio >= 0.75
flowShort = na(volumePressure) ? close < close[1] : volumePressure < 0 and volRatio >= 0.75
// Volatility percentile and ATR percentage are used to label market conditions and block extremes.
atrPct = close != 0 ? 100.0 * atr / close : na
volatilityRank = ta.percentrank(atrPct, volatilityLookback)
volatilityAllowed = not na(atrPct) and atrPct <= maxAtrPct and (na(volatilityRank) or volatilityRank <= maxVolatilityPercentile)
volatilityText = na(volatilityRank) ? "Warming up" : volatilityRank >= 80 ? "High" : volatilityRank <= 20 ? "Low" : "Normal"
rawLongScore = (qualLong ? 1 : 0) + (quantLong ? 1 : 0) + (strategyLong ? 1 : 0) + (flowLong ? 1 : 0) + (valueLong ? 1 : 0) + (autoContextLong ? 1 : 0) + (fundLong ? 1 : 0) + (volatilityAllowed ? 1 : 0) + candleLongBonus
rawShortScore = (qualShort ? 1 : 0) + (quantShort ? 1 : 0) + (strategyShort ? 1 : 0) + (flowShort ? 1 : 0) + (valueShort ? 1 : 0) + (autoContextShort ? 1 : 0) + (fundShort ? 1 : 0) + (volatilityAllowed ? 1 : 0) + candleShortBonus
longScore = int(math.max(0, math.min(9, rawLongScore + manualScoreAdjust)))
shortScore = int(math.max(0, math.min(9, rawShortScore - manualScoreAdjust)))
// ─────────────────────────────────────────────────────────────────────────────
// 4. VIRTUAL TRADE AND RISK ENGINE
// ─────────────────────────────────────────────────────────────────────────────
var int tradeDirection = 0
var float entryPrice = na
var float stopPrice = na
var float initialRisk = na
var float target1 = na
var float target2 = na
var float target3 = na
var bool target1Reached = false
var bool target2Reached = false
var int tradesToday = 0
var float dailyR = 0.0
var int wins = 0
var int losses = 0
var float sumR = 0.0
var int closedTrades = 0
var int lastDay = na
var string lastEvent = "Waiting for signal"
currentDay = year(time) * 10000 + month(time) * 100 + dayofmonth(time)
if na(lastDay) or currentDay != lastDay
lastDay := currentDay
tradesToday := 0
dailyR := 0.0
barReady = not confirmedOnly or barstate.isconfirmed
riskAllowed = volatilityAllowed and tradesToday < maxTradesDay and dailyR > -maxDailyLossR and atr > 0
longSetup = allowLong and longScore >= minScore and longScore > shortScore and riskAllowed and candleLongAllowed and barReady
shortSetup = allowShort and shortScore >= minScore and shortScore > longScore and riskAllowed and candleShortAllowed and barReady
// Conservative candle assumption: if a stop and target are both touched in one bar, count the stop first.
if tradeDirection != 0 and barReady
bool stopHit = tradeDirection == 1 ? low <= stopPrice : high >= stopPrice
bool hit1 = tradeDirection == 1 ? high >= target1 : low <= target1
bool hit2 = tradeDirection == 1 ? high >= target2 : low <= target2
bool hit3 = tradeDirection == 1 ? high >= target3 : low <= target3
bool oppositeSignal = tradeDirection == 1 ? shortSetup : longSetup
if stopHit
float exitR = tradeDirection == 1 ? (stopPrice - entryPrice) / initialRisk : (entryPrice - stopPrice) / initialRisk
float bookedR = target2Reached ? 0.33 * tp1R + 0.33 * tp2R + 0.34 * exitR : target1Reached ? 0.5 * tp1R + 0.5 * exitR : exitR
dailyR += bookedR
sumR += bookedR
closedTrades += 1
if bookedR > 0
wins += 1
else
losses += 1
lastEvent := bookedR > 0 ? "Trailing stop exit" : "Stop loss hit"
tradeDirection := 0
else
if hit1 and not target1Reached
target1Reached := true
stopPrice := entryPrice
lastEvent := "Target 1 reached · stop at breakeven"
if hit2 and target1Reached and not target2Reached
target2Reached := true
lastEvent := "Target 2 reached"
if hit3
float bookedR = 0.33 * tp1R + 0.33 * tp2R + 0.34 * tp3R
dailyR += bookedR
sumR += bookedR
closedTrades += 1
wins += 1
lastEvent := "Target 3 reached · trade closed"
tradeDirection := 0
else if oppositeSignal and tradeDirection != 0
float exitR = tradeDirection == 1 ? (close - entryPrice) / initialRisk : (entryPrice - close) / initialRisk
float bookedR = target2Reached ? 0.33 * tp1R + 0.33 * tp2R + 0.34 * exitR : target1Reached ? 0.5 * tp1R + 0.5 * exitR : exitR
dailyR += bookedR
sumR += bookedR
closedTrades += 1
if bookedR > 0
wins += 1
else
losses += 1
lastEvent := "Exit on opposite signal"
tradeDirection := 0
else if tradeDirection != 0 and target1Reached
float trailCandidate = tradeDirection == 1 ? close - atr * trailAtr : close + atr * trailAtr
stopPrice := tradeDirection == 1 ? math.max(stopPrice, trailCandidate) : math.min(stopPrice, trailCandidate)
newLong = tradeDirection == 0 and longSetup
newShort = tradeDirection == 0 and shortSetup
if newLong
tradeDirection := 1
entryPrice := close
initialRisk := atr * stopAtr
stopPrice := entryPrice - initialRisk
target1 := entryPrice + initialRisk * tp1R
target2 := entryPrice + initialRisk * tp2R
target3 := entryPrice + initialRisk * tp3R
target1Reached := false
target2Reached := false
tradesToday += 1
lastEvent := "Long entry"
else if newShort
tradeDirection := -1
entryPrice := close
initialRisk := atr * stopAtr
stopPrice := entryPrice + initialRisk
target1 := entryPrice - initialRisk * tp1R
target2 := entryPrice - initialRisk * tp2R
target3 := entryPrice - initialRisk * tp3R
target1Reached := false
target2Reached := false
tradesToday += 1
lastEvent := "Short entry"
riskCash = accountEquity * riskPct / 100.0
estimatedQuantity = not na(initialRisk) and initialRisk > 0 ? riskCash / initialRisk : na
// ─────────────────────────────────────────────────────────────────────────────
// 5. LIQUIDITY LINES AND SUPPLY/DEMAND ZONES
// ─────────────────────────────────────────────────────────────────────────────
var array<line> supplyLines = array.new_line()
var array<box> supplyBoxes = array.new_box()
var array<label> supplyLabels = array.new_label()
var array<line> demandLines = array.new_line()
var array<box> demandBoxes = array.new_box()
var array<label> demandLabels = array.new_label()
pivotHigh = ta.pivothigh(high, liquidityPivotLen, liquidityPivotLen)
pivotLow = ta.pivotlow(low, liquidityPivotLen, liquidityPivotLen)
if showLiquidity and not na(pivotHigh)
float pivotAtr = nz(atr[liquidityPivotLen], atr)
float supplyTop = pivotHigh
float supplyBottom = pivotHigh - pivotAtr * zoneAtrThickness
int pivotBar = bar_index - liquidityPivotLen
line newSupplyLine = line.new(pivotBar, pivotHigh, bar_index + liquidityLineLength, pivotHigh, xloc=xloc.bar_index, color=color.new(sellColor, liquidityLineTransparency), width=liquidityLineWidth, style=line.style_dashed)
box newSupplyBox = box.new(left=pivotBar, top=supplyTop, right=bar_index + liquidityLineLength, bottom=supplyBottom, xloc=xloc.bar_index, bgcolor=color.new(sellColor, liquidityBoxTransparency), border_color=color.new(sellColor, liquidityLineTransparency))
label newSupplyLabel = label.new(bar_index + liquidityLineLength, pivotHigh, "SUPPLY / BUY-SIDE LIQUIDITY", xloc=xloc.bar_index, style=label.style_label_left, color=color.new(sellColor, liquidityLineTransparency), textcolor=color.white, size=liqLabelSize)
array.push(supplyLines, newSupplyLine)
array.push(supplyBoxes, newSupplyBox)
array.push(supplyLabels, newSupplyLabel)
if array.size(supplyLines) > maxLiquidityZones
line.delete(array.shift(supplyLines))
box.delete(array.shift(supplyBoxes))
label.delete(array.shift(supplyLabels))
if showLiquidity and not na(pivotLow)
float pivotAtr = nz(atr[liquidityPivotLen], atr)
float demandBottom = pivotLow
float demandTop = pivotLow + pivotAtr * zoneAtrThickness
int pivotBar = bar_index - liquidityPivotLen
line newDemandLine = line.new(pivotBar, pivotLow, bar_index + liquidityLineLength, pivotLow, xloc=xloc.bar_index, color=color.new(buyColor, liquidityLineTransparency), width=liquidityLineWidth, style=line.style_dashed)
box newDemandBox = box.new(left=pivotBar, top=demandTop, right=bar_index + liquidityLineLength, bottom=demandBottom, xloc=xloc.bar_index, bgcolor=color.new(buyColor, liquidityBoxTransparency), border_color=color.new(buyColor, liquidityLineTransparency))
label newDemandLabel = label.new(bar_index + liquidityLineLength, pivotLow, "DEMAND / SELL-SIDE LIQUIDITY", xloc=xloc.bar_index, style=label.style_label_left, color=color.new(buyColor, liquidityLineTransparency), textcolor=color.white, size=liqLabelSize)
array.push(demandLines, newDemandLine)
array.push(demandBoxes, newDemandBox)
array.push(demandLabels, newDemandLabel)
if array.size(demandLines) > maxLiquidityZones
line.delete(array.shift(demandLines))
box.delete(array.shift(demandBoxes))
label.delete(array.shift(demandLabels))
if showLiquidity and array.size(supplyLines) > 0
for i = 0 to array.size(supplyLines) - 1
line.set_x2(array.get(supplyLines, i), bar_index + liquidityLineLength)
box.set_right(array.get(supplyBoxes, i), bar_index + liquidityLineLength)
label.set_x(array.get(supplyLabels, i), bar_index + liquidityLineLength)
if showLiquidity and array.size(demandLines) > 0
for i = 0 to array.size(demandLines) - 1
line.set_x2(array.get(demandLines, i), bar_index + liquidityLineLength)
box.set_right(array.get(demandBoxes, i), bar_index + liquidityLineLength)
label.set_x(array.get(demandLabels, i), bar_index + liquidityLineLength)
// ─────────────────────────────────────────────────────────────────────────────
// 6. CHART OUTPUTS AND ALERTS
// ─────────────────────────────────────────────────────────────────────────────
plot(showEMAs ? emaFast : na, "Fast EMA", color=trendColor, linewidth=1)
plot(showEMAs ? emaSlow : na, "Slow EMA", color=color.new(trendColor, 25), linewidth=2)
plot(showValue ? valueRef : na, "Value reference", color=valueColor, linewidth=2)
plot(showRiskLevels and tradeDirection != 0 ? stopPrice : na, "Active stop", color=sellColor, linewidth=2, style=plot.style_linebr)
plot(showRiskLevels and tradeDirection != 0 ? target1 : na, "Target 1", color=color.new(buyColor, 10), style=plot.style_linebr)
plot(showRiskLevels and tradeDirection != 0 ? target2 : na, "Target 2", color=color.new(buyColor, 25), style=plot.style_linebr)
plot(showRiskLevels and tradeDirection != 0 ? target3 : na, "Target 3", color=color.new(buyColor, 40), style=plot.style_linebr)
plotshape(newLong, title="Long entry", style=shape.triangleup, location=location.belowbar, color=buyColor, size=size.tiny)
plotshape(newShort, title="Short entry", style=shape.triangledown, location=location.abovebar, color=sellColor, size=size.tiny)
plotshape(showCandleMarkers and bullCandleConfirm, title="Bullish candle/VSA", style=shape.circle, location=location.belowbar, color=color.new(buyColor, 25), size=size.tiny)
plotshape(showCandleMarkers and bearCandleConfirm, title="Bearish candle/VSA", style=shape.circle, location=location.abovebar, color=color.new(sellColor, 25), size=size.tiny)
alertcondition(newLong, "Talenta Samurai · Long", "Talenta Samurai: confirmed LONG signal")
alertcondition(newShort, "Talenta Samurai · Short", "Talenta Samurai: confirmed SHORT signal")
alertcondition(lastEvent == "Stop loss hit" and lastEvent[1] != "Stop loss hit", "Talenta Samurai · Stop loss", "Talenta Samurai: stop loss hit")
alertcondition(lastEvent == "Trailing stop exit" and lastEvent[1] != "Trailing stop exit", "Talenta Samurai · Trailing stop", "Talenta Samurai: trailing stop hit")
alertcondition(lastEvent == "Target 1 reached · stop at breakeven" and lastEvent[1] != "Target 1 reached · stop at breakeven", "Talenta Samurai · Target 1", "Talenta Samurai: Target 1 reached; stop moved to breakeven")
alertcondition(lastEvent == "Target 2 reached" and lastEvent[1] != "Target 2 reached", "Talenta Samurai · Target 2", "Talenta Samurai: Target 2 reached")
alertcondition(lastEvent == "Target 3 reached · trade closed" and lastEvent[1] != "Target 3 reached · trade closed", "Talenta Samurai · Target 3", "Talenta Samurai: Target 3 reached; trade closed")
alertcondition(lastEvent == "Exit on opposite signal" and lastEvent[1] != "Exit on opposite signal", "Talenta Samurai · Exit", "Talenta Samurai: position closed on opposite signal")
// ─────────────────────────────────────────────────────────────────────────────
// 7. INFORMATION PANEL
// ─────────────────────────────────────────────────────────────────────────────
var table panel = table.new(position.top_right, 2, 15, border_width=1)
if barstate.isfirst
table.merge_cells(panel, 0, 14, 1, 14)
if showPanel and barstate.islast
float winRate = closedTrades > 0 ? 100.0 * wins / closedTrades : na
float avgR = closedTrades > 0 ? sumR / closedTrades : na
string stateText = tradeDirection == 1 ? "Long" : tradeDirection == -1 ? "Short" : "Flat"
color stateColor = tradeDirection == 1 ? buyColor : tradeDirection == -1 ? sellColor : color.gray
table.cell(panel, 0, 0, "TALENTA SAMURAI", bgcolor=color.rgb(30, 35, 45), text_color=color.white)
table.cell(panel, 1, 0, "PROPRIETARY SUITE", bgcolor=color.rgb(30, 35, 45), text_color=color.white)
table.cell(panel, 0, 1, "Signal score")
table.cell(panel, 1, 1, str.tostring(longScore) + " Long / " + str.tostring(shortScore) + " Short")
table.cell(panel, 0, 2, "Trend / higher timeframe")
table.cell(panel, 1, 2, strategyLong ? "Bullish" : strategyShort ? "Bearish" : "Neutral")
table.cell(panel, 0, 3, "Candle / VSA")
table.cell(panel, 1, 3, candleStatus)
table.cell(panel, 0, 4, "Cross-market context")
table.cell(panel, 1, 4, contextText)
table.cell(panel, 0, 5, "Company fundamentals")
table.cell(panel, 1, 5, fundamentalText)
table.cell(panel, 0, 6, "Volatility regime")
table.cell(panel, 1, 6, volatilityText + " · ATR " + str.tostring(atrPct, "#.##") + "%")
table.cell(panel, 0, 7, "Price vs value")
table.cell(panel, 1, 7, close > valueRef ? "Above" : close < valueRef ? "Below" : "At reference")
table.cell(panel, 0, 8, "Manual score adjustment")
table.cell(panel, 1, 8, str.tostring(manualScoreAdjust))
table.cell(panel, 0, 9, "Daily result / trades")
table.cell(panel, 1, 9, str.tostring(dailyR, "#.##") + " R / " + str.tostring(tradesToday))
table.cell(panel, 0, 10, "Virtual position")
table.cell(panel, 1, 10, stateText, text_color=stateColor)
table.cell(panel, 0, 11, "Closed-trade win rate")
table.cell(panel, 1, 11, na(winRate) ? "—" : str.tostring(winRate, "#.0") + "%")
table.cell(panel, 0, 12, "Average result")
table.cell(panel, 1, 12, na(avgR) ? "—" : str.tostring(avgR, "#.##") + " R")
table.cell(panel, 0, 13, "Last event / est. quantity")
table.cell(panel, 1, 13, lastEvent + " / " + (na(estimatedQuantity) ? "—" : str.tostring(estimatedQuantity, "#.####")))
table.cell(panel, 0, 14, "Educational only · Not investment advice · No orders · Trading involves risk", text_color=color.silver, text_size=size.tiny)