//-------------------------------------------------//
//PRC_TASC Issue: January 2026
// Article: Identifying Peaks And Valleys In Ranging Markets - The Reversion Index
// Article By: John F. Ehlers
//version = 0
//17.12.25
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//-------------------------------------------------//
// --- Parameters ---
//-------------------------------------------------//
length = 20
riSmooth = 8
trSmooth = 4
//-------------------------------------------------//
// --- Reversion Index Calculation ---
//-------------------------------------------------//
// Logic: Ratio of net price change to total absolute price change
priceChange = Close - Close[1]
sumChange = Summation[length](priceChange)
sumAbsChange = Summation[length](ABS(priceChange))
// ratio calculation with division by zero protection
ri = 0
IF sumAbsChange <> 0 THEN
ri = sumChange / sumAbsChange
ENDIF
//-------------------------------------------------//
// --- Super Smoother Filter Logic ---
//-------------------------------------------------//
// 1. Calculation for "Smooth" (sm) using riSmooth period
//-------------------------------------------------//
PIValue = 3.14159
// Alpha and Beta calculations
Alpha1 = (PIValue * SQRT(2)) / riSmooth
Beta1 = EXP(-Alpha1)
// Coefficients
Coef21 = -1 * SQUARE(Beta1)
// Convert Radians to Degrees
AlphaDeg1 = Alpha1 * 180 / PIValue
Coef11 = COS(AlphaDeg1) * 2 * Beta1
Coef01 = 1 - Coef11 - Coef21
// Filter calculation
// sma2 is the average of current and previous input
sma21 = (ri + ri[1]) / 2
IF BarIndex < length + 2 THEN
sm = 0
ELSE
// Recursive calculation: uses previous values of sm
sm = (Coef01 * sma21) + (Coef11 * sm[1]) + (Coef21 * sm[2])
ENDIF
//-------------------------------------------------//
// 2. Calculation for "Trigger" (tr) using trSmooth period
//-------------------------------------------------//
Alpha2 = (PIValue * SQRT(2)) / trSmooth
Beta2 = EXP(-Alpha2)
Coef22 = -1 * SQUARE(Beta2)
// Convert Radians to Degrees
AlphaDeg2 = Alpha2 * 180 / PIValue
Coef12 = COS(AlphaDeg2) * 2 * Beta2
Coef02 = 1 - Coef12 - Coef22
sma22 = (ri + ri[1]) / 2
IF BarIndex < length + 2 THEN
mytr = 0
ELSE
mytr = (Coef02 * sma22) + (Coef12 * mytr[1]) + (Coef22 * mytr[2])
ENDIF
//-------------------------------------------------//
RETURN 0 AS "Zero Level", sm COLOURED(255, 0, 0) AS "Smooth", mytr COLOURED(0, 0, 255) AS "Trigger"