Paste the Pine v6 indicator into TradingView Pine Editor and add it to an ordinary candlestick chart. UTR marks a completed candidate. On the next completed bar only, C records a close above the full pattern high, F records a close below the full pattern low, and E records neither. This one-bar follow-through window is an example test, not part of the named pattern.
Custom rules: closed-bar candidates, separate next-bar outcomes, no strategy orders.pine
//@version=6
indicator("Unique three river: explicit research rules", overlay = true)
length = input.int(10, "Prior body average", minval = 1)
shortFactor = input.float(0.5, "Third body / average maximum", minval = 0.01, maxval = 1.0)
shadowFactor = input.float(2.0, "Second lower shadow / body minimum", minval = 0.0)
body = math.abs(close - open)
priorMean = ta.sma(body, length)[1]
valid = not na(open) and not na(high) and not na(low) and not na(close) and high >= math.max(open, close) and low <= math.min(open, close)
ready = not na(priorMean[2]) and not na(close[5]) and valid and valid[1] and valid[2]
priorDecline = close[5] > close[4] and close[4] > close[3]
first = close[2] < open[2] and body[2] > priorMean[2]
secondBody = close[1] < open[1] and close[1] > close[2] and open[1] <= open[2]
secondLow = low[1] < low[2] and close[1] - low[1] >= shadowFactor * body[1]
third = close > open and body < shortFactor * priorMean and open > low[1] and close < close[1]
candidate = barstate.isconfirmed and ready and priorDecline and first and secondBody and secondLow and third
patternHigh = math.max(high, math.max(high[1], high[2]))
patternLow = math.min(low, math.min(low[1], low[2]))
confirmed = barstate.isconfirmed and candidate[1] and close > patternHigh[1]
failed = barstate.isconfirmed and candidate[1] and close < patternLow[1]
expired = barstate.isconfirmed and candidate[1] and not confirmed and not failed
plotshape(candidate, title = "Candidate", style = shape.circle, location = location.belowbar, color = color.blue, text = "UTR", size = size.tiny)
plotshape(confirmed, title = "Next-bar confirmation", style = shape.triangleup, location = location.belowbar, color = color.green, text = "C", size = size.tiny)
plotshape(failed, title = "Next-bar invalidation", style = shape.xcross, location = location.abovebar, color = color.red, text = "F", size = size.tiny)
plotshape(expired, title = "Expired after next bar", style = shape.square, location = location.belowbar, color = color.gray, text = "E", size = size.tiny)
alertcondition(candidate, "Unique three river candidate", "Unique three river candidate on a completed bar")