Reversion Index

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #254594 quote
    regusregus
    Participant
    Veteran

    Please can someone convert this indicator from Tradingview.

    // TASC Issue: January 2026

    // Article: Identifying Peaks And Valleys In Ranging Markets

    // The Reversion Index

    // Article By: John F. Ehlers

    // Language: TradingView’s Pine Script® v6

    // Provided By: PineCoders, for tradingview.com

    //@version=6

    indicator(“TASC 2026.01 The Reversion Index”, “RI”, overlay = false)

    //#region Inputs

    int length = input.int(20, title = “RI Length”, tooltip = “Normalization Length of Data.”)

    riSmooth = 8

    trSmooth = 4

    //#endregion

    //#region Functions

    // Reversion Index

    reversionIndex (int length) =>

    float d = close – close[1]

    float ds = math.sum(d, length)

    float ads = math.sum(math.abs(d), length)

    float ratio = ads != 0.0 ? ds / ads : 0.0

    ratio

    // Super Smoother Filter

    superSmoother(float Series, float Period) =>

    var float ALPHA = math.pi * math.sqrt(2.0) / Period

    var float BETA = math.exp(-ALPHA )

    var float COEF2 = -math.pow(BETA, 2)

    var float COEF1 = math.cos( ALPHA ) * 2.0 * BETA

    var float COEF0 = 1.0 – COEF1 – COEF2

    float sma2 = math.avg(Series, nz(Series[1], Series))

    float smooth = na, smooth := COEF0 * sma2 +

    COEF1 * nz(smooth[1]) +

    COEF2 * nz(smooth[2])

    //#endregion

    //#region Calculations

    float ri = reversionIndex(length)

    float sm = superSmoother(ri, riSmooth)

    float tr = superSmoother(ri, trSmooth)

    //#endregion

    //#region Display

    hline(0)

    plot(sm, “Smooth”, color.red)

    plot(tr, “Trigger”, color.blue)

    //#endregion

    #254608 quote
    Iván GonzálezIván González
    Moderator
    Legend
    Here it is:
    //-------------------------------------------------//
    //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"
    regus thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

TradingView to ProRealTime Translation Center

New Reply
Author
author-avatar
regus @regus Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván GonzálezIván González
9 months, 1 week ago.

Topic Details
Forum: TradingView to ProRealTime Translation Center Forum
Started: 12/17/2025
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...