Indicator · Pine Script v6 · On the chart

3CandleWarEng

by theonetrade

3CandleWarEng is an overlay indicator that identifies three-candle price pattern setups alongside integrated order block detection and a moving average trend filter.

View on GitHub

Repaints

GitHub stars34on the repository
Pine versionv6current
Lines of code488
Settings40inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

488 lines of Pine Script v6 from assets/indicator/bit-exact/3candlewar_7zls7Hw3.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

3candlewar_7zls7Hw3.pine
//@version=6
indicator("3CandleWarEng", overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=500)

// ============================================================
// INPUT
// ============================================================
grpLines    = "C1 Lines"
showLines   = input.bool(true, "Show C1 High/Low lines", group=grpLines)
maxHistory  = input.int(50, "Confirmed setups (C1-C2-C3 completed) to keep on chart", minval=5, maxval=200, group=grpLines)
lineColor   = input.color(color.new(color.gray, 60), "Line color (C1 waiting for C2)", group=grpLines)
setupColor  = input.color(color.new(color.fuchsia, 0), "Line color (C2 valid, waiting for C3)", group=grpLines)

grpSig      = "Pattern Signals"
showBuy     = input.bool(true,  "Show BUY signals", group=grpSig)
showSell    = input.bool(true,  "Show SELL signals (mirrored)", group=grpSig)
buyColor    = input.color(color.yellow, "Buy star color", group=grpSig)
sellColor   = input.color(color.red,    "Sell star color", group=grpSig)
closeToleranceATR = input.float(0.01, "C3 close tolerance vs C1 (in ATR, 0 = clean close)", minval=0, step=0.01, group=grpSig)

grpMA       = "Moving Average Filter"
useMaFilter = input.bool(true, "Enable trend filter with moving average", group=grpMA)
maTF        = input.timeframe("5", "MA timeframe", group=grpMA)
maLen       = input.int(20, "SMA period", minval=1, group=grpMA)
maSrc       = input.source(close, "Source", group=grpMA)
showMaPlot  = input.bool(true, "Show MA on chart", group=grpMA)
maDynamicColor = input.bool(true, "Dynamic MA color based on trend", group=grpMA)
maColorUp   = input.color(color.lime, "MA color (price above)", group=grpMA)
maColorDown = input.color(color.red,  "MA color (price below)", group=grpMA)
maColorFlat = input.color(color.aqua, "MA color (fixed, if dynamic off)", group=grpMA)

grpOB           = "Order Block"
obEnable        = input.bool(true, "Enable Order Block detection", group=grpOB)
showObBoxes     = input.bool(true, "Show Order Block boxes on chart", group=grpOB)
obRealtimeDraw  = input.bool(true, "Draw OB on forming candle too (repainting)", group=grpOB)
useDisplacement = input.bool(true, "Require displacement (strong breakout)", group=grpOB)
atrLen          = input.int(14, "ATR period (displacement)", minval=1, group=grpOB)
dispMult        = input.float(1.2, "ATR multiplier for displacement", minval=0.1, step=0.1, group=grpOB)
obBoxCount      = input.int(5, "Max OB per side on chart", minval=1, maxval=20, group=grpOB)
obMitigateOnClose = input.bool(true, "Mitigation on close (otherwise on wick)", group=grpOB)
obProximityATR  = input.float(0.5, "'Nearby' margin (in ATR)", minval=0, step=0.1, group=grpOB)
obBypassMaOnTouch = input.bool(true, "Bypass MA filter if C1 or C2 touch a matching OB", group=grpOB)
obBorderTransp  = input.int(70, "OB border transparency (0 = solid, 100 = invisible)", minval=0, maxval=100, group=grpOB)
bullObColor     = input.color(color.new(color.teal, 80), "Bullish OB box color", group=grpOB)
bearObColor     = input.color(color.new(color.orange, 80), "Bearish OB box color", group=grpOB)
warnColor       = input.color(color.new(color.fuchsia, 0), "Warning label color (opposite OB)", group=grpOB)

grpTouch          = "OB Touch Label"
showOBTouchLabel  = input.bool(true, "Show 'OB' only on first touch of an important Order Block", group=grpTouch)
obTouchMinSizeATR = input.float(1.0, "Minimum OB size to be 'important' (in ATR)", minval=0, step=0.1, group=grpTouch)
obTouchMaxLabels  = input.int(100, "Max OB Touch labels on chart", minval=5, maxval=500, group=grpTouch)

grpTrade        = "Trade Levels (SL/TP)"
showTradeBox    = input.bool(true, "Draw SL/TP boxes on confirmed signal", group=grpTrade)
rrRatio         = input.float(2.0, "Take Profit ratio (R:R)", minval=0.5, step=0.5, group=grpTrade)
minAtrStopMult  = input.float(0.5, "Minimum SL distance beyond C1 (in ATR)", minval=0, step=0.1, group=grpTrade)
tradeBoxBars    = input.int(30, "Box extension to the right (bars)", minval=1, group=grpTrade)
maxTradeBoxes   = input.int(10, "Max trade boxes on chart", minval=1, maxval=50, group=grpTrade)
tpBoxColor      = input.color(color.new(color.green, 85), "Take Profit box color", group=grpTrade)
slBoxColor      = input.color(color.new(color.red, 85), "Stop Loss box color", group=grpTrade)
tradeBorderTransp = input.int(40, "SL/TP box border transparency (0 = solid, 100 = invisible)", minval=0, maxval=100, group=grpTrade)
entryLineColor  = input.color(color.new(color.white, 20), "Entry line color", group=grpTrade)
showTradeLabel  = input.bool(false, "Show Entry/SL/TP label", group=grpTrade)

grpDbg      = "Debug"
dbgOB       = input.bool(false, "Debug: show OB touch state on C1/C2 and C3 tolerance", group=grpDbg)

// ============================================================
// STATE
// ============================================================
var int   state       = 0
var float c1High      = na
var float c1Low       = na
var line  c1HiLine    = na
var line  c1LoLine    = na
var bool  isBuySetup  = false
var bool  isSellSetup = false

// Flag: C1 or C2 touched a matching OB
var bool c1c2TouchedBullOB = false
var bool c1c2TouchedBearOB = false

// OB anti-duplicate per bar
var int lastBullOBBar = -1
var int lastBearOBBar = -1

var line[] histHi = array.new_line()
var line[] histLo = array.new_line()

// Trade levels (SL/TP)
var box[]   tpBoxes    = array.new_box()
var box[]   slBoxes    = array.new_box()
var line[]  entryLines = array.new_line()
var label[] rrLabels   = array.new_label()

// "OB" label on first important touch
var label[] obTouchLabels  = array.new_label()

// reset every bar
buySignal   = false
sellSignal  = false
buyNearOB   = false
sellNearOB  = false
buyWarnOB   = false
sellWarnOB  = false

// ============================================================
// MOVING AVERAGE ON CUSTOM TIMEFRAME (trend filter) + dynamic color
// ============================================================
maValue = request.security(syminfo.tickerid, maTF, ta.sma(maSrc, maLen), lookahead=barmerge.lookahead_off)

maPlotColor = maDynamicColor ? (close > maValue ? maColorUp : close < maValue ? maColorDown : maColorFlat) : maColorFlat

plot(showMaPlot ? maValue : na, title="SMA Filter", color=maPlotColor, linewidth=2)

aboveMa = not useMaFilter or close > maValue
belowMa = not useMaFilter or close < maValue

// ============================================================
// ORDER BLOCK: data structures
// ============================================================
var box[]   bullBoxes    = array.new_box()
var float[] bullTop      = array.new_float()
var float[] bullBottom   = array.new_float()
var bool[]  bullTouched  = array.new_bool()

var box[]   bearBoxes    = array.new_box()
var float[] bearTop      = array.new_float()
var float[] bearBottom   = array.new_float()
var bool[]  bearTouched  = array.new_bool()

atrVal = ta.atr(atrLen)

// ============================================================
// ORDER BLOCK: mitigation (confirmed bars only)
// ============================================================
if barstate.isconfirmed and obEnable
    if array.size(bullBoxes) > 0
        for i = array.size(bullBoxes) - 1 to 0
            bx  = array.get(bullBoxes, i)
            bot = array.get(bullBottom, i)
            box.set_right(bx, bar_index)
            mitigated = obMitigateOnClose ? close < bot : low < bot
            if mitigated
                box.delete(bx)
                array.remove(bullBoxes, i)
                array.remove(bullTop, i)
                array.remove(bullBottom, i)
                array.remove(bullTouched, i)

    if array.size(bearBoxes) > 0
        for i = array.size(bearBoxes) - 1 to 0
            bx  = array.get(bearBoxes, i)
            top = array.get(bearTop, i)
            box.set_right(bx, bar_index)
            mitigated = obMitigateOnClose ? close > top : high > top
            if mitigated
                box.delete(bx)
                array.remove(bearBoxes, i)
                array.remove(bearTop, i)
                array.remove(bearBottom, i)
                array.remove(bearTouched, i)

// ============================================================
// ORDER BLOCK: creation (real-time or confirmed bar only)
// ============================================================
if obEnable and (obRealtimeDraw or barstate.isconfirmed)
    // --- Bullish OB ---
    bullishOB = close[1] < open[1] and close > high[1] and (not useDisplacement or (close - open) > atrVal * dispMult)
    if bullishOB and bar_index != lastBullOBBar
        obTop = high[1]
        obBot = low[1]
        newBoxBull = box.new(left=bar_index[1], top=obTop, right=bar_index, bottom=obBot, border_color=color.new(bullObColor, obBorderTransp), bgcolor=showObBoxes ? bullObColor : na)
        array.push(bullBoxes, newBoxBull)
        array.push(bullTop, obTop)
        array.push(bullBottom, obBot)
        array.push(bullTouched, false)
        lastBullOBBar := bar_index
        if array.size(bullBoxes) > obBoxCount
            box.delete(array.shift(bullBoxes))
            array.shift(bullTop)
            array.shift(bullBottom)
            array.shift(bullTouched)

    // --- Bearish OB ---
    bearishOB = close[1] > open[1] and close < low[1] and (not useDisplacement or (open - close) > atrVal * dispMult)
    if bearishOB and bar_index != lastBearOBBar
        obTop = high[1]
        obBot = low[1]
        newBoxBear = box.new(left=bar_index[1], top=obTop, right=bar_index, bottom=obBot, border_color=color.new(bearObColor, obBorderTransp), bgcolor=showObBoxes ? bearObColor : na)
        array.push(bearBoxes, newBoxBear)
        array.push(bearTop, obTop)
        array.push(bearBottom, obBot)
        array.push(bearTouched, false)
        lastBearOBBar := bar_index
        if array.size(bearBoxes) > obBoxCount
            box.delete(array.shift(bearBoxes))
            array.shift(bearTop)
            array.shift(bearBottom)
            array.shift(bearTouched)

// ============================================================
// OB CHECK FUNCTIONS
// ============================================================
// Check if a price (px) is inside or near an OB box
f_nearAnyBox(tops, bottoms, px, margin) =>
    bool found = false
    if array.size(tops) > 0
        for i = 0 to array.size(tops) - 1
            t = array.get(tops, i)
            b = array.get(bottoms, i)
            if px <= t + margin and px >= b - margin
                found := true
    found

// Check if the [lo, hi] range of a candle overlaps an OB box
f_overlapsAnyBox(tops, bottoms, lo, hi, margin) =>
    bool found = false
    if array.size(tops) > 0
        for i = 0 to array.size(tops) - 1
            t = array.get(tops, i)
            b = array.get(bottoms, i)
            if hi >= b - margin and lo <= t + margin
                found := true
    found

// Check the FIRST touch on "important" OBs (size >= ATR threshold) and mark the box as already signalled
f_checkImportantTouch(tops, bottoms, touched, lo, hi, minSizeATR, atrV) =>
    bool anyNewTouch = false
    if array.size(tops) > 0
        for i = 0 to array.size(tops) - 1
            already = array.get(touched, i)
            if not already
                t = array.get(tops, i)
                b = array.get(bottoms, i)
                sizeOK  = (t - b) >= atrV * minSizeATR
                overlap = hi >= b and lo <= t
                if sizeOK and overlap
                    array.set(touched, i, true)
                    anyNewTouch := true
    anyNewTouch

// ============================================================
// "OB" LABEL ONLY ON FIRST TOUCH OF AN IMPORTANT OB
// ============================================================
if showOBTouchLabel and obEnable and showObBoxes
    newBullTouch = f_checkImportantTouch(bullTop, bullBottom, bullTouched, low, high, obTouchMinSizeATR, atrVal)
    newBearTouch = f_checkImportantTouch(bearTop, bearBottom, bearTouched, low, high, obTouchMinSizeATR, atrVal)
    if newBullTouch or newBearTouch
        obTouchLbl = label.new(bar_index, high, text="OB", style=label.style_label_down,
             color=color.new(color.white, 100), textcolor=color.white, size=size.tiny)
        array.push(obTouchLabels, obTouchLbl)
        if array.size(obTouchLabels) > obTouchMaxLabels
            label.delete(array.shift(obTouchLabels))

// ============================================================
// TRADE DRAWING FUNCTION (SL/TP boxes + entry line + R:R label)
// ============================================================
f_drawTrade(isLong, entryPx, slPx) =>
    riskDist  = math.abs(entryPx - slPx)
    tpPx      = isLong ? entryPx + riskDist * rrRatio : entryPx - riskDist * rrRatio
    boxRight  = bar_index + tradeBoxBars

    tBox = box.new(left=bar_index, top=isLong ? tpPx : entryPx, right=boxRight,
         bottom=isLong ? entryPx : tpPx, border_color=color.new(color.green, tradeBorderTransp), bgcolor=tpBoxColor)
    sBox = box.new(left=bar_index, top=isLong ? entryPx : slPx, right=boxRight,
         bottom=isLong ? slPx : entryPx, border_color=color.new(color.red, tradeBorderTransp), bgcolor=slBoxColor)
    eLine = line.new(bar_index, entryPx, boxRight, entryPx, color=entryLineColor, width=1, style=line.style_dashed)
    rrTxt = "Entry: " + str.tostring(entryPx, "#.#####") + "\nSL: " + str.tostring(slPx, "#.#####") +
         "\nTP: " + str.tostring(tpPx, "#.#####") + "\nR:R = 1:" + str.tostring(rrRatio, "#.#")
    lbl = label.new(boxRight, entryPx, text=rrTxt, style=label.style_label_left,
         color=color.new(color.black, 100),
         textcolor=showTradeLabel ? color.white : color.new(color.white, 100),
         size=size.tiny)

    array.push(tpBoxes, tBox)
    array.push(slBoxes, sBox)
    array.push(entryLines, eLine)
    array.push(rrLabels, lbl)

    if array.size(tpBoxes) > maxTradeBoxes
        box.delete(array.shift(tpBoxes))
        box.delete(array.shift(slBoxes))
        line.delete(array.shift(entryLines))
        label.delete(array.shift(rrLabels))

// ============================================================
// REAL-TIME CHECK (every tick, not only on confirmed bar)
// ============================================================
if state == 2
    margin = atrVal * obProximityATR
    tolC3  = atrVal * closeToleranceATR

    buyBase  = isBuySetup  and low  >= c1Low  and high >= c1High and close > c1High - tolC3
    sellBase = isSellSetup and high <= c1High and low  <= c1Low  and close < c1Low  + tolC3

    buyNearOBcheck  = obEnable and buyBase  and f_nearAnyBox(bullTop, bullBottom, close, margin)
    sellNearOBcheck = obEnable and sellBase and f_nearAnyBox(bearTop, bearBottom, close, margin)

    buyWarnOBcheck  = obEnable and buyBase  and f_nearAnyBox(bearTop, bearBottom, close, margin)
    sellWarnOBcheck = obEnable and sellBase and f_nearAnyBox(bullTop, bullBottom, close, margin)

    buyBypassMa  = obEnable and obBypassMaOnTouch and c1c2TouchedBullOB
    sellBypassMa = obEnable and obBypassMaOnTouch and c1c2TouchedBearOB

    buyConfirm  = buyBase  and (aboveMa or buyNearOBcheck  or buyBypassMa)
    sellConfirm = sellBase and (belowMa or sellNearOBcheck or sellBypassMa)

    if buyConfirm and showBuy
        buySignal := true
        buyNearOB := buyNearOBcheck
        buyWarnOB := buyWarnOBcheck
    if sellConfirm and showSell
        sellSignal := true
        sellNearOB := sellNearOBcheck
        sellWarnOB := sellWarnOBcheck

// ============================================================
// STATEFUL LOGIC (confirmed bar only)
// ============================================================
if barstate.isconfirmed
    if state == 0
        c1High   := high
        c1Low    := low
        c1c2TouchedBullOB := false
        c1c2TouchedBearOB := false
        if obEnable
            marginC1 = atrVal * obProximityATR
            if f_overlapsAnyBox(bullTop, bullBottom, low, high, marginC1)
                c1c2TouchedBullOB := true
            if f_overlapsAnyBox(bearTop, bearBottom, low, high, marginC1)
                c1c2TouchedBearOB := true
        if showLines
            c1HiLine := line.new(bar_index, high, bar_index + 2, high, xloc=xloc.bar_index, color=lineColor, width=1)
            c1LoLine := line.new(bar_index, low,  bar_index + 2, low,  xloc=xloc.bar_index, color=lineColor, width=1)
        state := 1

    else if state == 1
        brokeDown = low  < c1Low
        brokeUp   = high > c1High
        reclaimed = close >= c1Low and close <= c1High
        buySetup  = brokeDown and not brokeUp and reclaimed
        sellSetup = brokeUp and not brokeDown and reclaimed

        if obEnable and (buySetup or sellSetup)
            marginC2 = atrVal * obProximityATR
            if f_overlapsAnyBox(bullTop, bullBottom, low, high, marginC2)
                c1c2TouchedBullOB := true
            if f_overlapsAnyBox(bearTop, bearBottom, low, high, marginC2)
                c1c2TouchedBearOB := true

        if buySetup or sellSetup
            isBuySetup  := buySetup
            isSellSetup := sellSetup
            if showLines and not na(c1HiLine)
                line.set_color(c1HiLine, setupColor)
                line.set_color(c1LoLine, setupColor)
            state := 2
        else
            if not na(c1HiLine)
                line.delete(c1HiLine)
                line.delete(c1LoLine)
            c1High := high
            c1Low  := low
            c1c2TouchedBullOB := false
            c1c2TouchedBearOB := false
            if obEnable
                marginC1 = atrVal * obProximityATR
                if f_overlapsAnyBox(bullTop, bullBottom, low, high, marginC1)
                    c1c2TouchedBullOB := true
                if f_overlapsAnyBox(bearTop, bearBottom, low, high, marginC1)
                    c1c2TouchedBearOB := true
            if showLines
                c1HiLine := line.new(bar_index, high, bar_index + 2, high, xloc=xloc.bar_index, color=lineColor, width=1)
                c1LoLine := line.new(bar_index, low,  bar_index + 2, low,  xloc=xloc.bar_index, color=lineColor, width=1)
            else
                c1HiLine := na
                c1LoLine := na
            state := 1

    else if state == 2
        margin = atrVal * obProximityATR
        tolC3F = atrVal * closeToleranceATR

        buyBaseFinal  = isBuySetup  and low  >= c1Low  and high >= c1High and close > c1High - tolC3F
        sellBaseFinal = isSellSetup and high <= c1High and low  <= c1Low  and close < c1Low  + tolC3F

        buyNearOBFinal  = obEnable and buyBaseFinal  and f_nearAnyBox(bullTop, bullBottom, close, margin)
        sellNearOBFinal = obEnable and sellBaseFinal and f_nearAnyBox(bearTop, bearBottom, close, margin)

        buyBypassMaFinal  = obEnable and obBypassMaOnTouch and c1c2TouchedBullOB
        sellBypassMaFinal = obEnable and obBypassMaOnTouch and c1c2TouchedBearOB

        buyConfirmFinal  = buyBaseFinal  and (aboveMa or buyNearOBFinal  or buyBypassMaFinal)
        sellConfirmFinal = sellBaseFinal and (belowMa or sellNearOBFinal or sellBypassMaFinal)

        if dbgOB
            label.new(bar_index, high,
                 text="C1C2 BullOB=" + str.tostring(c1c2TouchedBullOB) + "\nC1C2 BearOB=" + str.tostring(c1c2TouchedBearOB) +
                      "\nC1 low=" + str.tostring(c1Low, "#.#####") + " C1 high=" + str.tostring(c1High, "#.#####") +
                      "\nC3 low=" + str.tostring(low, "#.#####") + " close=" + str.tostring(close, "#.#####") +
                      "\ntol=" + str.tostring(tolC3F, "#.#####") +
                      "\nsellBase=" + str.tostring(sellBaseFinal) + " buyBase=" + str.tostring(buyBaseFinal) +
                      "\nsellConfirm=" + str.tostring(sellConfirmFinal) + " buyConfirm=" + str.tostring(buyConfirmFinal),
                 style=label.style_label_down, color=color.new(color.blue, 60), textcolor=color.white, size=size.tiny)

        // --- Draw SL/TP on confirmed signal (non-repainting) ---
        if showTradeBox and buyConfirmFinal
            slPx = c1Low - atrVal * minAtrStopMult
            f_drawTrade(true, close, slPx)

        if showTradeBox and sellConfirmFinal
            slPx = c1High + atrVal * minAtrStopMult
            f_drawTrade(false, close, slPx)

        if buyConfirmFinal or sellConfirmFinal
            if not na(c1HiLine)
                array.push(histHi, c1HiLine)
                array.push(histLo, c1LoLine)
                while array.size(histHi) > maxHistory
                    line.delete(array.shift(histHi))
                    line.delete(array.shift(histLo))
            isBuySetup  := false
            isSellSetup := false
            c1c2TouchedBullOB := false
            c1c2TouchedBearOB := false
            state       := 0
        else
            if not na(c1HiLine)
                line.delete(c1HiLine)
                line.delete(c1LoLine)
            isBuySetup  := false
            isSellSetup := false
            c1High := high
            c1Low  := low
            c1c2TouchedBullOB := false
            c1c2TouchedBearOB := false
            if obEnable
                marginC1 = atrVal * obProximityATR
                if f_overlapsAnyBox(bullTop, bullBottom, low, high, marginC1)
                    c1c2TouchedBullOB := true
                if f_overlapsAnyBox(bearTop, bearBottom, low, high, marginC1)
                    c1c2TouchedBearOB := true
            if showLines
                c1HiLine := line.new(bar_index, high, bar_index + 2, high, xloc=xloc.bar_index, color=lineColor, width=1)
                c1LoLine := line.new(bar_index, low,  bar_index + 2, low,  xloc=xloc.bar_index, color=lineColor, width=1)
            else
                c1HiLine := na
                c1LoLine := na
            state := 1

// ============================================================
// SIGNAL PLOT
// ============================================================
plotchar(buySignal,  title="Buy Star",  char="★", location=location.belowbar, color=buyColor,  size=size.small)
plotchar(sellSignal, title="Sell Star", char="★", location=location.abovebar, color=sellColor, size=size.small)

if buyNearOB
    label.new(bar_index, low,  text="OB", style=label.style_label_up,   color=color.new(bullObColor, 0), textcolor=color.white, size=size.tiny)
if sellNearOB
    label.new(bar_index, high, text="OB", style=label.style_label_down, color=color.new(bearObColor, 0), textcolor=color.white, size=size.tiny)

if buyWarnOB
    label.new(bar_index, high, text="⚠OB", style=label.style_label_down, color=warnColor, textcolor=color.white, size=size.tiny)
if sellWarnOB
    label.new(bar_index, low,  text="⚠OB", style=label.style_label_up,   color=warnColor, textcolor=color.white, size=size.tiny)

if buySignal
    alert("BUY confirmed on " + syminfo.ticker, alert.freq_once_per_bar)
if sellSignal
    alert("SELL confirmed on " + syminfo.ticker, alert.freq_once_per_bar)
if buyNearOB
    alert("BUY confirmed + Order Block confluence on " + syminfo.ticker, alert.freq_once_per_bar)
if sellNearOB
    alert("SELL confirmed + Order Block confluence on " + syminfo.ticker, alert.freq_once_per_bar)
if buyWarnOB
    alert("WARNING: BUY near a bearish Order Block (possible reversal) on " + syminfo.ticker, alert.freq_once_per_bar)
if sellWarnOB
    alert("WARNING: SELL near a bullish Order Block (possible reversal) on " + syminfo.ticker, alert.freq_once_per_bar)

alertcondition(isBuySetup  and state == 2, title="Buy Setup Pending",  message="Low sweep + reclaim: waiting for C3 confirmation")
alertcondition(isSellSetup and state == 2, title="Sell Setup Pending", message="High sweep + reclaim: waiting for C3 confirmation")
alertcondition(buySignal,  title="Buy Confirmed",  message="C3 confirmed: BUY pattern completed")
alertcondition(sellSignal, title="Sell Confirmed", message="C3 confirmed: SELL pattern completed")
alertcondition(buyNearOB,  title="Buy + Order Block", message="BUY confirmed in confluence with Order Block")
alertcondition(sellNearOB, title="Sell + Order Block", message="SELL confirmed in confluence with Order Block")
alertcondition(buyWarnOB,  title="Buy - Opposite OB Warning", message="BUY near a bearish Order Block: reversal risk")
alertcondition(sellWarnOB, title="Sell - Opposite OB Warning", message="SELL near a bullish Order Block: reversal risk")
alertcondition(showOBTouchLabel, title="Important OB Touch", message="First candle touching an important Order Block")

Overview

3CandleWarEng plots reference lines for setup stages, triggers buy and sell signal stars, and highlights bullish or bearish order blocks defined by ATR displacement thresholds. Key options allow users to toggle trend filters, adjust ATR multipliers, configure order block mitigation settings, and display touch labels. The indicator can draw order blocks on the live forming bar, which repaints until the bar closes.

Details

Published by

theonetrade on GitHub

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Show C1 High/Low linesbooltrueshowLines
Confirmed setups (C1-C2-C3 completed) to keep on chartint50maxHistory
Line color (C1 waiting for C2)colorcolor.new(color.gray, 60)lineColor
Line color (C2 valid, waiting for C3)colorcolor.new(color.fuchsia, 0)setupColor
Show BUY signalsbooltrueshowBuy
Show SELL signals (mirrored)booltrueshowSell
Buy star colorcolorcolor.yellowbuyColor
Sell star colorcolorcolor.redsellColor
C3 close tolerance vs C1 (in ATR, 0 = clean close)float0.01closeToleranceATR
Enable trend filter with moving averagebooltrueuseMaFilter
MA timeframetimeframe5maTF
SMA periodint20maLen
Show all 40 settings
SettingTypeDefaultVariable
SourcesourceclosemaSrc
Show MA on chartbooltrueshowMaPlot
Dynamic MA color based on trendbooltruemaDynamicColor
MA color (price above)colorcolor.limemaColorUp
MA color (price below)colorcolor.redmaColorDown
MA color (fixed, if dynamic off)colorcolor.aquamaColorFlat
Enable Order Block detectionbooltrueobEnable
Show Order Block boxes on chartbooltrueshowObBoxes
Draw OB on forming candle too (repainting)booltrueobRealtimeDraw
Require displacement (strong breakout)booltrueuseDisplacement
ATR period (displacement)int14atrLen
ATR multiplier for displacementfloat1.2dispMult
Max OB per side on chartint5obBoxCount
Mitigation on close (otherwise on wick)booltrueobMitigateOnClose
'Nearby' margin (in ATR)float0.5obProximityATR
Bypass MA filter if C1 or C2 touch a matching OBbooltrueobBypassMaOnTouch
OB border transparency (0 = solid, 100 = invisible)int70obBorderTransp
Bullish OB box colorcolorcolor.new(color.teal, 80)bullObColor
Bearish OB box colorcolorcolor.new(color.orange, 80)bearObColor
Warning label color (opposite OB)colorcolor.new(color.fuchsia, 0)warnColor
Show 'OB' only on first touch of an important Order BlockbooltrueshowOBTouchLabel
Minimum OB size to be 'important' (in ATR)float1.0obTouchMinSizeATR
Max OB Touch labels on chartint100obTouchMaxLabels
Draw SL/TP boxes on confirmed signalbooltrueshowTradeBox
Take Profit ratio (R:R)float2.0rrRatio
Minimum SL distance beyond C1 (in ATR)float0.5minAtrStopMult
Box extension to the right (bars)int30tradeBoxBars
Max trade boxes on chartint10maxTradeBoxes
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This overlay indicator detects tweezer tops and bottoms and kangaroo-tail pin bars, then draws supply and demand zones from those patterns. It scores each zone, decays freshness, merges overlapping zones, and can invalidate a zone after a close-through or afte

Indicator v6 Candlestick patternsSupport & resistance
Updated 4 weeks ago · MIT GitHub repository of Tweezer & Kangaroo Zones [WavesUnchained]
7 stars

This indicator plots Smart Money Concepts and price action components directly on the price chart. It highlights bullish and bearish order blocks, multi-timeframe pivot points, market structure swings with key Fibonacci retracement levels (0.618 and 0.786), zo

Indicator v5 SMC / ICT / price actionSupport & resistance Repaints
Updated 4 months ago · None stated GitHub repository of Cryptokazancev Strategy Pack
3 stars

This Pine Script indicator plots Smart Money Concepts market structure directly on the price chart. It identifies swing highs and lows, internal market structures, Break of Structure events, Change of Character shifts, and EQH/EQL levels. Breaker blocs are hig

Indicator v5 SMC / ICT / price actionCandlestick patterns Repaints
Updated 1 year ago · None stated GitHub repository of SMC & Breaker Blocs [Krishna]

Price Action Toolkit

by TamTH-Dev
2 stars

The Price Action Toolkit is an indicator that combines several price action tools on the chart. It calculates the ATR with user-defined length and shows it in a table. It plots multiple Kaufman Adaptive Moving Averages (KAMA) with different lengths and sources

Indicator v6 TrendSupport & resistance
Updated 2 months ago · None stated GitHub repository of Price Action Toolkit

Smart Money Concepts [LuxAlgo]

by srinivas-yarramsetti
2 stars

This indicator plots Smart Money Concepts elements on the price chart including internal and swing order blocks, bullish and bearish structures with BOS and CHoCH breaks, fair value gaps, equal highs and lows, and swing points. It can color candles according t

Indicator v5 SMC / ICT / price actionCandlestick patterns Repaints
Updated 3 years ago · None stated GitHub repository of Smart Money Concepts [LuxAlgo]

j14-E1 adv

by moonyroy
1 stars

This indicator plots ZigZag lines connecting swing highs and lows to map price structure. It draws candle body and shadow boxes on the price chart and detects CHoCH for potential trend shifts and BOS for continuation signals. The main setting toggles candle di

Indicator v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 3 weeks ago · None stated GitHub repository of j14-E1 adv

More Candlestick patterns scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers