Set Opposite directional bars to 1, 2 or 3. All state updates are gated by barstate.isconfirmed, which TradingView documents as true on historical bars and the closing update of a realtime bar. There is no negative plot offset and no label backdated to the pivot candle. The code is an indicator, not a trading strategy.
Pineify Gann-style v1. The newest gray extreme remains provisional until a reversal confirms. Syntax validation checks compilation, not equivalence to other Gann products or profitability.pine
//@version=6
// Pineify educational Gann-style reference v1, 2026-10-18.
// Strict directional bars; inside/equality pause; outside resets count.
indicator("Gann-style v1: confirmation-time events", overlay = true, max_labels_count = 500)
int n = input.int(2, "Opposite directional bars", minval = 1, maxval = 3)
var int direction = 0
var int count = 0
var float extreme = na
var int extremeBar = na
var float pending = na
var int pendingBar = na
float pivot = na
int pivotBar = na
bool flipUp = false
bool flipDown = false
bool valid = not na(high) and not na(low) and high >= low
bool previousValid = not na(high[1]) and not na(low[1]) and high[1] >= low[1]
if barstate.isconfirmed
if not valid or not previousValid
direction := 0
count := 0
extreme := na
extremeBar := na
pending := na
pendingBar := na
else
bool upBar = high > high[1] and low > low[1]
bool downBar = high < high[1] and low < low[1]
bool outside = high > high[1] and low < low[1]
int step = upBar ? 1 : downBar ? -1 : 0
if direction == 0
if step != 0
direction := step
extreme := step == 1 ? high : low
extremeBar := bar_index
else
bool extends = direction == 1 ? high > extreme : low < extreme
if extends
extreme := direction == 1 ? high : low
extremeBar := bar_index
if outside or step == direction or extends
count := 0
pending := na
pendingBar := na
if not outside and step == -direction
count += 1
float candidate = direction == 1 ? low : high
if count == 1 or (direction == 1 ? candidate < pending : candidate > pending)
pending := candidate
pendingBar := bar_index
else if count > 0
float candidate = direction == 1 ? low : high
if direction == 1 ? candidate < pending : candidate > pending
pending := candidate
pendingBar := bar_index
if count >= n
pivot := extreme
pivotBar := extremeBar
direction := -direction
flipUp := direction == 1
flipDown := direction == -1
extreme := pending
extremeBar := pendingBar
count := 0
pending := na
pendingBar := na
if not na(pivot)
string kind = flipDown ? "High" : "Low"
label.new(bar_index, pivot, kind + " pivot index " + str.tostring(pivotBar) + " confirmed now", style = flipDown ? label.style_label_down : label.style_label_up, color = flipDown ? color.red : color.blue, textcolor = color.white)
plot(direction == 0 ? na : extreme, "Developing extreme at observation time", color.gray, style = plot.style_stepline)
plot(pivot, "Pivot price on confirmation bar", color.orange, 3, plot.style_circles)
plot(direction, "Direction: up 1, down -1", display = display.data_window)
plot(count, "Pending opposite count", display = display.data_window)
plot(pivotBar, "Confirmed pivot bar index", display = display.data_window)
alertcondition(flipUp, "Confirmed upswing", "Gann-style v1 upswing confirmed at bar close")
alertcondition(flipDown, "Confirmed downswing", "Gann-style v1 downswing confirmed at bar close")