本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// Talenta Harami + Hammer Reversal Signals
// Volume bubbles are percentile-based OHLCV proxies, not exchange aggressor data.
// All setup state and signals are committed only after a bar closes.
indicator("Talenta · Harami, Hammer & Volume Bubbles", shorttitle="Talenta H/H Bubbles", overlay=true, max_labels_count=200, max_bars_back=2000)
// ─────────────────────────────────────────────────────────────────────────────
// Inputs
string gPattern = "01 · Padrões"
bool showOnlyHaramiDoji = input.bool(true, "Show Only Harami Style Doji's", group=gPattern, tooltip="Mantém apenas dojis contidos no candle anterior após sequência direcional. Esses padrões também podem armar e gerar sinais, desde que haja contexto de preço e bubble de volume.")
bool enableHarami = input.bool(true, "Usar Harami Style Doji", group=gPattern)
bool enableHammer = input.bool(true, "Usar Hammer e Hammer invertido", group=gPattern)
bool showPatternMarks = input.bool(true, "Marcar padrões no gráfico", group=gPattern)
int priorBars = input.int(3, "Candles direcionais anteriores", minval=1, maxval=3, group=gPattern)
float dojiBodyMax = input.float(35, "Corpo máximo do doji (% do range)", minval=5, maxval=60, step=1, group=gPattern)
float dojiWickMin = input.float(20, "Cada pavio mínimo do doji (% do range)", minval=5, maxval=45, step=1, group=gPattern)
float hammerBodyMax = input.float(40, "Corpo máximo do hammer (% do range)", minval=5, maxval=60, step=1, group=gPattern)
float hammerWickRatio = input.float(2.0, "Pavio principal / corpo mínimo", minval=1.2, maxval=8, step=0.1, group=gPattern)
string gContext = "02 · Price action, Fibonacci e liquidez"
int moveLen = input.int(8, "Queda/alta prévia: N candles", minval=2, maxval=100, group=gContext)
float moveMinATR = input.float(1.5, "Movimento prévio mínimo (ATR)", minval=0.2, maxval=10, step=0.1, group=gContext)
int fibLen = input.int(80, "Janela para níveis Fibonacci/liquidez", minval=10, maxval=500, group=gContext)
float fibZoneATR = input.float(0.35, "Raio da região Fibonacci (ATR)", minval=0.05, maxval=2, step=0.05, group=gContext)
int pivotLen = input.int(8, "Janela do rompimento de estrutura", minval=2, maxval=100, group=gContext)
int setupExpiry = input.int(8, "Validade do setup para rompimento (candles)", minval=1, maxval=50, group=gContext)
bool showFibLevels = input.bool(false, "Exibir níveis Fibonacci estimados", group=gContext, tooltip="Níveis móveis calculados sobre a janela anterior, sem usar o candle atual. São zonas de referência, não pivôs confirmados.")
string gVolume = "03 · Volume bubble"
bool requireBubble = input.bool(true, "Exigir bubble de volume para sinal", group=gVolume)
int volShortLen = input.int(20, "Janela curta", minval=5, maxval=200, group=gVolume)
int volMidLen = input.int(50, "Janela média", minval=10, maxval=500, group=gVolume)
int volLongLen = input.int(100, "Janela longa", minval=20, maxval=1000, group=gVolume)
float bubblePercentile = input.float(85, "Percentil mínimo de volume", minval=50, maxval=99, step=1, group=gVolume)
string bubbleConsensus = input.string("2 de 3", "Consenso das janelas", options=["1 de 3", "2 de 3", "3 de 3"], group=gVolume)
bool showBubbles = input.bool(true, "Mostrar bubbles de volume", group=gVolume)
string gVisual = "04 · Visual ultra tech"
color buyColor = input.color(#00E5FF, "BUY / ciano", group=gVisual)
color sellColor = input.color(#FF3D9A, "SELL / magenta", group=gVisual)
color bubbleNeutral = input.color(#B58CFF, "Bubble misto", group=gVisual)
bool showEntrySignals = input.bool(true, "Mostrar sinais BUY / SELL", group=gVisual)
// ─────────────────────────────────────────────────────────────────────────────
// Utilities and non-repainting context
float candleRange = math.max(high - low, syminfo.mintick)
float body = math.abs(close - open)
float upperWick = high - math.max(open, close)
float lowerWick = math.min(open, close) - low
float atr = ta.atr(14)
float bodyPct = body / candleRange * 100.0
bool priorBear = true
bool priorBull = true
for i = 1 to priorBars
priorBear := priorBear and close[i] < open[i]
priorBull := priorBull and close[i] > open[i]
float priorHigh = ta.highest(high[1], fibLen)
float priorLow = ta.lowest(low[1], fibLen)
float fibRange = math.max(priorHigh - priorLow, syminfo.mintick)
float buyFib50 = priorHigh - fibRange * 0.500
float buyFib618 = priorHigh - fibRange * 0.618
float buyFib786 = priorHigh - fibRange * 0.786
float sellFib382 = priorLow + fibRange * 0.382
float sellFib50 = priorLow + fibRange * 0.500
float sellFib618 = priorLow + fibRange * 0.618
float buyExtension127 = priorLow - fibRange * 0.272
float sellExtension127 = priorHigh + fibRange * 0.272
float zone = math.max(nz(atr) * fibZoneATR, syminfo.mintick)
f_near(float x, float level, float radius) => not na(level) and math.abs(x - level) <= radius
bool buyFibZone = f_near(low, buyFib50, zone) or f_near(low, buyFib618, zone) or f_near(low, buyFib786, zone)
bool sellFibZone = f_near(high, sellFib382, zone) or f_near(high, sellFib50, zone) or f_near(high, sellFib618, zone)
// A close back inside the previous range after taking its extreme is a liquidity sweep/reclaim.
bool buyLiquiditySweep = low < priorLow and close > priorLow
bool sellLiquiditySweep = high > priorHigh and close < priorHigh
bool buyExtensionReaction = low <= buyExtension127 and close > buyExtension127
bool sellExtensionReaction = high >= sellExtension127 and close < sellExtension127
float dropATR = atr > 0 and not na(close[moveLen]) ? (close[moveLen] - close) / atr : 0.0
float riseATR = atr > 0 and not na(close[moveLen]) ? (close - close[moveLen]) / atr : 0.0
bool priorStrongDrop = dropATR >= moveMinATR
bool priorStrongRise = riseATR >= moveMinATR
float priorPivotHigh = ta.highest(high[1], pivotLen)
float priorPivotLow = ta.lowest(low[1], pivotLen)
bool bullishStructureBreak = not na(priorPivotHigh) and close > priorPivotHigh and close[1] <= priorPivotHigh
bool bearishStructureBreak = not na(priorPivotLow) and close < priorPivotLow and close[1] >= priorPivotLow
// ─────────────────────────────────────────────────────────────────────────────
// Pattern recognition: same-color preceding candles plus body containment for Harami.
bool dojiShape = bodyPct <= dojiBodyMax and upperWick / candleRange * 100.0 >= dojiWickMin and lowerWick / candleRange * 100.0 >= dojiWickMin
bool containedInPreviousBody = math.max(open, close) <= math.max(open[1], close[1]) and math.min(open, close) >= math.min(open[1], close[1])
bool haramiBull = dojiShape and containedInPreviousBody and priorBear
bool haramiBear = dojiShape and containedInPreviousBody and priorBull
bool genericBullDoji = dojiShape and priorBear and not haramiBull and not haramiBear
bool genericBearDoji = dojiShape and priorBull and not haramiBull and not haramiBear
float safeBody = math.max(body, syminfo.mintick)
bool hammerShape = bodyPct <= hammerBodyMax and lowerWick >= safeBody * hammerWickRatio and upperWick <= safeBody * 0.8
bool invertedHammerShape = bodyPct <= hammerBodyMax and upperWick >= safeBody * hammerWickRatio and lowerWick <= safeBody * 0.8
bool hammerBull = hammerShape and priorStrongDrop
bool hammerBear = invertedHammerShape and priorStrongRise
bool selectedBullPattern = (enableHarami and haramiBull) or (not showOnlyHaramiDoji and enableHarami and genericBullDoji) or (enableHammer and hammerBull)
bool selectedBearPattern = (enableHarami and haramiBear) or (not showOnlyHaramiDoji and enableHarami and genericBearDoji) or (enableHammer and hammerBear)
// ─────────────────────────────────────────────────────────────────────────────
// Volume bubbles: multi-window percentile consensus, matching the attached example's
// relative-volume clusters without external lower-timeframe dependencies.
float pShort = ta.percentile_linear_interpolation(volume, volShortLen, bubblePercentile)
float pMid = ta.percentile_linear_interpolation(volume, volMidLen, bubblePercentile)
float pLong = ta.percentile_linear_interpolation(volume, volLongLen, bubblePercentile)
int volHits = (not na(pShort) and volume >= pShort ? 1 : 0) + (not na(pMid) and volume >= pMid ? 1 : 0) + (not na(pLong) and volume >= pLong ? 1 : 0)
int requiredHits = bubbleConsensus == "1 de 3" ? 1 : bubbleConsensus == "3 de 3" ? 3 : 2
bool volumeBubble = volHits >= requiredHits and not na(volume) and volume > 0
float avgVolume = ta.sma(volume, volMidLen)
float rvol = avgVolume > 0 ? volume / avgVolume : na
float closeLocation = (close - low) / candleRange
bool bubbleBuyPressure = closeLocation >= 0.60
bool bubbleSellPressure = closeLocation <= 0.40
color bubbleColor = bubbleBuyPressure ? color.new(buyColor, 12) : bubbleSellPressure ? color.new(sellColor, 12) : color.new(bubbleNeutral, 12)
bool dataReady = not na(priorHigh) and not na(priorLow) and not na(atr)
// Context can validate immediately at a Fib/liquidity reaction, or arm a setup
// after a strong leg and wait for a later close through the pattern's extreme.
bool bullRejection = closeLocation >= 0.60
bool bearRejection = closeLocation <= 0.40
bool bullDirectContext = (buyFibZone or buyLiquiditySweep or buyExtensionReaction) and bullRejection
bool bearDirectContext = (sellFibZone or sellLiquiditySweep or sellExtensionReaction) and bearRejection
bool bullContext = bullDirectContext or priorStrongDrop
bool bearContext = bearDirectContext or priorStrongRise
bool bubbleOK = not requireBubble or volumeBubble
bool confirmed = barstate.isconfirmed and dataReady
// Setups are frozen at the confirmed pattern bar; later breakouts cannot repaint.
var float pendingBuyHigh = na
var float pendingBuyLow = na
var int pendingBuyBar = na
var bool pendingBuyDirect = false
var float pendingSellHigh = na
var float pendingSellLow = na
var int pendingSellBar = na
var bool pendingSellDirect = false
bool buyPatternSeed = confirmed and selectedBullPattern and bullContext and bubbleOK
bool sellPatternSeed = confirmed and selectedBearPattern and bearContext and bubbleOK
bool buyDirectSignal = buyPatternSeed and bullDirectContext
bool sellDirectSignal = sellPatternSeed and bearDirectContext
bool buyBreakSignal = confirmed and not na(pendingBuyBar) and bar_index > pendingBuyBar and bar_index - pendingBuyBar <= setupExpiry and close > pendingBuyHigh and (bullishStructureBreak or close > open)
bool sellBreakSignal = confirmed and not na(pendingSellBar) and bar_index > pendingSellBar and bar_index - pendingSellBar <= setupExpiry and close < pendingSellLow and (bearishStructureBreak or close < open)
bool buySignal = buyDirectSignal or buyBreakSignal
bool sellSignal = sellDirectSignal or sellBreakSignal
if confirmed
if not na(pendingBuyBar) and (bar_index - pendingBuyBar > setupExpiry or close < pendingBuyLow - zone)
pendingBuyBar := na
pendingBuyHigh := na
pendingBuyLow := na
pendingBuyDirect := false
if not na(pendingSellBar) and (bar_index - pendingSellBar > setupExpiry or close > pendingSellHigh + zone)
pendingSellBar := na
pendingSellHigh := na
pendingSellLow := na
pendingSellDirect := false
if buySignal
pendingBuyBar := na
pendingBuyHigh := na
pendingBuyLow := na
pendingBuyDirect := false
if sellSignal
pendingSellBar := na
pendingSellHigh := na
pendingSellLow := na
pendingSellDirect := false
if buyPatternSeed and not buyDirectSignal
pendingBuyHigh := high
pendingBuyLow := low
pendingBuyBar := bar_index
pendingBuyDirect := false
if sellPatternSeed and not sellDirectSignal
pendingSellHigh := high
pendingSellLow := low
pendingSellBar := bar_index
pendingSellDirect := false
// ─────────────────────────────────────────────────────────────────────────────
// Visuals
plot(showFibLevels ? buyFib50 : na, "Fib compra 0.50", color=color.new(buyColor, 65), linewidth=1, style=plot.style_linebr)
plot(showFibLevels ? buyFib618 : na, "Fib compra 0.618", color=color.new(buyColor, 45), linewidth=1, style=plot.style_linebr)
plot(showFibLevels ? buyFib786 : na, "Fib compra 0.786", color=color.new(buyColor, 65), linewidth=1, style=plot.style_linebr)
plot(showFibLevels ? sellFib382 : na, "Fib venda 0.382", color=color.new(sellColor, 65), linewidth=1, style=plot.style_linebr)
plot(showFibLevels ? sellFib50 : na, "Fib venda 0.50", color=color.new(sellColor, 45), linewidth=1, style=plot.style_linebr)
plot(showFibLevels ? sellFib618 : na, "Fib venda 0.618", color=color.new(sellColor, 65), linewidth=1, style=plot.style_linebr)
plot(showFibLevels ? buyExtension127 : na, "Extensão compra 1.272", color=color.new(buyColor, 30), linewidth=1, style=plot.style_linebr)
plot(showFibLevels ? sellExtension127 : na, "Extensão venda 1.272", color=color.new(sellColor, 30), linewidth=1, style=plot.style_linebr)
plotshape(showBubbles and confirmed and volumeBubble and volHits == 1 ? hl2 : na, title="Bubble volume médio", style=shape.circle, location=location.absolute, color=bubbleColor, size=size.small)
plotshape(showBubbles and confirmed and volumeBubble and volHits == 2 ? hl2 : na, title="Bubble volume alto", style=shape.circle, location=location.absolute, color=bubbleColor, size=size.normal)
plotshape(showBubbles and confirmed and volumeBubble and volHits == 3 ? hl2 : na, title="Bubble volume extremo", style=shape.circle, location=location.absolute, color=bubbleColor, size=size.large)
plotshape(showPatternMarks and confirmed and haramiBull, title="Harami Doji comprador", text="HD", style=shape.labelup, location=location.belowbar, color=color.new(buyColor, 75), textcolor=buyColor, size=size.tiny)
plotshape(showPatternMarks and confirmed and haramiBear, title="Harami Doji vendedor", text="HD", style=shape.labeldown, location=location.abovebar, color=color.new(sellColor, 75), textcolor=sellColor, size=size.tiny)
plotshape(showPatternMarks and not showOnlyHaramiDoji and confirmed and genericBullDoji, title="Doji comprador", text="D", style=shape.circle, location=location.belowbar, color=color.new(buyColor, 55), textcolor=buyColor, size=size.tiny)
plotshape(showPatternMarks and not showOnlyHaramiDoji and confirmed and genericBearDoji, title="Doji vendedor", text="D", style=shape.circle, location=location.abovebar, color=color.new(sellColor, 55), textcolor=sellColor, size=size.tiny)
plotshape(showPatternMarks and confirmed and hammerBull, title="Hammer comprador", text="HAM", style=shape.labelup, location=location.belowbar, color=color.new(buyColor, 80), textcolor=buyColor, size=size.tiny)
plotshape(showPatternMarks and confirmed and hammerBear, title="Hammer invertido vendedor", text="IH", style=shape.labeldown, location=location.abovebar, color=color.new(sellColor, 80), textcolor=sellColor, size=size.tiny)
plotshape(showEntrySignals and buySignal and confirmed, title="BUY confirmado", style=shape.triangleup, location=location.belowbar, color=buyColor, size=size.tiny)
plotshape(showEntrySignals and sellSignal and confirmed, title="SELL confirmado", style=shape.triangledown, location=location.abovebar, color=sellColor, size=size.tiny)
alertcondition(buySignal and confirmed, title="Talenta BUY · Harami/Hammer", message="BUY confirmado: padrão reversivo, price action/Fibonacci/liquidez e volume bubble alinhados.")
alertcondition(sellSignal and confirmed, title="Talenta SELL · Harami/Hammer", message="SELL confirmado: padrão reversivo, price action/Fibonacci/liquidez e volume bubble alinhados.")
var table status = table.new(position.top_right, 2, 4, bgcolor=color.new(#07111F, 8), frame_color=color.new(#00E5FF, 45), border_color=color.new(#243B55, 15))
if barstate.islast
table.cell(status, 0, 0, "TALENTA · REVERSAL", text_color=#00E5FF, bgcolor=color.new(#0B1D31, 0))
table.cell(status, 1, 0, "FLOW / PA", text_color=#FF3D9A, bgcolor=color.new(#0B1D31, 0))
table.cell(status, 0, 1, "Volume bubble", text_color=color.silver)
table.cell(status, 1, 1, volumeBubble ? "ATIVO · " + str.tostring(rvol, "#.##") + "x" : "—", text_color=volumeBubble ? bubbleColor : color.gray)
table.cell(status, 0, 2, "Fib / liquidez", text_color=color.silver)
table.cell(status, 1, 2, buyFibZone or buyLiquiditySweep or buyExtensionReaction ? "ZONA BUY" : sellFibZone or sellLiquiditySweep or sellExtensionReaction ? "ZONA SELL" : "NEUTRO", text_color=buyFibZone or buyLiquiditySweep or buyExtensionReaction ? buyColor : sellFibZone or sellLiquiditySweep or sellExtensionReaction ? sellColor : color.gray)
table.cell(status, 0, 3, "Setup pendente", text_color=color.silver)
table.cell(status, 1, 3, not na(pendingBuyBar) ? "BUY · aguarda rompimento" : not na(pendingSellBar) ? "SELL · aguarda rompimento" : "—", text_color=not na(pendingBuyBar) ? buyColor : not na(pendingSellBar) ? sellColor : color.gray)