Skip to main content
On this page

Kairi Relative Index: Formula, Threshold Crosses and Pine Example

· 4 min read
Pineify Team
Pine Script and AI trading workflow research team

The Kairi Relative Index (KRI) measures percentage distance from a moving average. A positive value means the selected price is above that average; a negative value means it is below. It does not establish that a stretched price must return to the average.

Kairi Relative Index Indicator - TradingView Chart

Formula and interpretation​

For the close-based SMA version used here:

KRI = 100 × (Close − SMA(Close, length)) / SMA(Close, length)

If the close is 105 and the average is 100, KRI is +5%. If the close is 95, it is −5%. These are arithmetic examples. The average must be available and nonzero. A 14-bar average means fourteen chart bars, not fourteen days on every timeframe.

KRI is unbounded, unlike RSI's usual 0–100 scale. Universal thresholds such as ±8%, ±15% or ±20% are not established for every stock and timeframe. Inspect the distribution using development data, record a proposed threshold and evaluate it on separate data.

Correctly distinguish entering and leaving an extreme​

Crossing below a negative threshold enters the lower extreme. Crossing above that threshold exits it. The earlier condition “below −10 now, at or above −10 previously” described entering the extreme, not bouncing out of it.

This complete indicator marks closed-bar returns from illustrative thresholds. It does not place strategy orders:

//@version=6
indicator("Kairi threshold transitions", overlay=false)
int length = input.int(14, "SMA length", minval=1)
float lower = input.float(-5.0, "Lower threshold")
float upper = input.float(5.0, "Upper threshold")
if lower >= upper
runtime.error("Lower threshold must be below upper threshold")
float average = ta.sma(close, length)
float kri = not na(average) and average != 0.0 ? 100.0 * (close - average) / average : na
bool crossedUp = ta.crossover(kri, lower)
bool crossedDown = ta.crossunder(kri, upper)
bool returnFromLow = barstate.isconfirmed and crossedUp
bool returnFromHigh = barstate.isconfirmed and crossedDown
plot(kri, "KRI", color=color.blue)
hline(0, "Zero", color=color.gray)
hline(lower, "Lower", color=color.green)
hline(upper, "Upper", color=color.red)
plotshape(returnFromLow, "Return from lower extreme", shape.triangleup, location.bottom, color.green, size=size.tiny)
plotshape(returnFromHigh, "Return from upper extreme", shape.triangledown, location.top, color.red, size=size.tiny)

The ±5 inputs demonstrate transitions; they are not optimized settings. The line itself can change during a forming candle, while the markers require confirmation. See TradingView's bar-state documentation for that distinction.

The Best Pine Script Generator

Test the hypothesis separately from the display​

Pineify Website
How to search for and add indicator pages in the Pineify editor

Pineify includes a Kairi calculation using close and its SMA. To turn an indicator condition into a strategy, additionally define order timing, position size, exits, stops and costs. Inspect the resulting trade list in the strategy test rather than treating a marker as a fill.

Compare threshold-return rules against zero-crossing rules on the same data. A trend filter changes which trades are included; it does not guarantee fewer losing trades. No SPY Sharpe ratio or AAPL, TSLA or NVDA observation is verified here. Record the full method before claiming a result.

FAQ​

Does a negative KRI mean buy?
No. It means price is below its average. Price can continue falling, and a threshold rule needs separate evaluation.
Is 14 the best length?
It is an example length, not a universal optimum. Changing it changes both the reference average and the distribution of KRI values.
How is KRI different from RSI?
KRI is percentage distance from an average. RSI transforms relative average gains and losses into a bounded oscillator. Their thresholds are not interchangeable.