This chart-timeframe indicator exposes both powers, the denominator and confirmed state in the Data Window. The TTF line develops during the open bar; only the state, markers and alert conditions wait for confirmation. There are no strategy orders or higher-timeframe requests.
Educational implementation of the stated window and state rules. Syntax checking does not prove numerical agreement with other scripts or profitable trades.pine
//@version=6
indicator("Trend Trigger Factor window audit", overlay=false, precision=4)
length = input.int(15, "Bars per window", minval=1, maxval=500)
threshold = input.float(100.0, "Symmetric threshold", minval=0.1)
recentHigh = ta.highest(high, length)
recentLow = ta.lowest(low, length)
olderHigh = recentHigh[length]
olderLow = recentLow[length]
validBar = not na(high) and not na(low) and high >= low
validFraction = ta.sma(validBar ? 1.0 : 0.0, 2 * length)
fullWindow = bar_index >= 2 * length - 1 and validFraction == 1.0
buyPower = recentHigh - olderLow
sellPower = olderHigh - recentLow
denominator = 0.5 * (buyPower + sellPower)
ttf = fullWindow and denominator > 0.0 ? 100.0 * (buyPower - sellPower) / denominator : na
var int direction = 0
bool switchedUp = false
bool switchedDown = false
if barstate.isconfirmed and not na(ttf)
nextDirection = ttf > threshold ? 1 : ttf < -threshold ? -1 : direction
switchedUp := nextDirection == 1 and direction != 1
switchedDown := nextDirection == -1 and direction != -1
direction := nextDirection
plot(ttf, "TTF (developing until close)", color=color.blue, style=plot.style_linebr)
hline(threshold, "Upper threshold", color=color.gray)
hline(-threshold, "Lower threshold", color=color.gray)
hline(0, "Zero", color=color.gray, linestyle=hline.style_dotted)
plot(buyPower, "Buy power", display=display.data_window)
plot(sellPower, "Sell power", display=display.data_window)
plot(denominator, "Average window range", display=display.data_window)
plot(direction, "Confirmed direction: -1, 0, 1", display=display.data_window)
plotshape(switchedUp, title="Switch to up", style=shape.triangleup, location=location.bottom, color=color.green, size=size.tiny)
plotshape(switchedDown, title="Switch to down", style=shape.triangledown, location=location.top, color=color.red, size=size.tiny)
alertcondition(switchedUp, "Confirmed TTF switch up", "TTF direction switched up on a closed chart bar.")
alertcondition(switchedDown, "Confirmed TTF switch down", "TTF direction switched down on a closed chart bar.")