detailed RSI calculation

Discussion in 'Technical Analysis' started by citizen_halo, Oct 16, 2002.

  1. I am using wilder's simple RSI formula (Eup/Eup+Edown) where E=summation

    here is my simple code

    rsi() is an array, it's size is dependent on period, in this case is 14, it samples price every minute, not SMAed nor EMAed, not averaged. could this be a problem?

    Do

    If rsi(i - 1) - rsi(i) > 0 Then

    cu = cu + (rsi(i - 1) - rsi(i))
    End If

    If rsi(i - 1) - rsi(i) < 0 Then

    cd = cd + (rsi(i) - rsi(i - 1))
    End If

    i = i - 1

    Loop Until i = 0

    rsi=cu/cu+cd

    the problem with this code/formula is inherent, when price change is very small, the RSI swings can be extreme from 0 to 100, How can I smooth my RSI without much lag. any help appreciated.
     
  2. I personally like the RSI as a momentum indicator. The best RSI that I have seen (low lag and smooth) is the Jurik RSI. You can smooth a regular RSI with weighted, exponential or regular averages but they won't be nearly as good as the Jurik RSI. You can come fairly close using the regular RSI smoothed with a more adaptive average such as the T3Average.
     
  3. googled on jurik RSI, no formula or pseudo code. could you provide the published formula if it's ok to do so. also is the adaptive average based on previous RSI delta? if not, I don't see how it can help with the lag.
     
  4. Look into the Ehlers Optimized RSI. He uses digital signal processing methods and applies it to the RSI. Less momemtum is used with the indicator and there is greater emphasis on changes in phase cycles.

    The other thing I can recomend is identifying support levels in normal RSIs and adapting the oversold and overbought conditions to bear or bull markets.
     
  5. Mark Jurik sells proprietary tools. You have to buy to use those. There is no free code posted for these anywhere. His JMA average and RSI are the best I've seen in terms of smoothness and low lag.

    You originally asked about smoothing an RSI. Anytime you apply smoothing to a number series you have a tradeoff between lag and smoothness. The raw RSI is lag free, but isn't very smooth. An average of the RSI will smooth the RSI, but will introduce some lag into the equation. Adaptive averages will lessen the lag while giving more smoothness.

    If you want to find the T3Average, do a search in the TradeStation archives (choose ARCHIVE SEARCH) on the keyword "T3Average" all years, and look for the code posted by Bob Fulks.

    http://purebytes.com/archives/
     
  6. In addition I recently coded up the T3Average in VB based on the code provided by Bob Fulks. I'll post the code here in case you're interested.

    Code:
    Public Function T3Average_Double(Price() As Double, ByVal Period As Long, Indicator() As Double)
    Dim ctr&, ub&, LB&
    Dim E1#, E2#, E3#, E4#, E5#, E6#
    Dim XAlpha#, XBeta#, OldPeriod&
    Dim Damp&, b#, aa#, aaa#, c1#, c2#, c3#, c4#
        LB = Period - 1
        ub = UBound(Price)
        ReDim Indicator(ub)
        Damp = -70
        b = Damp * -0.01
        aa = b * b
        aaa = b * b * b
        c1 = -aaa
        c2 = 3 * aa + 3 * aaa
        c3 = -6 * aa - 3 * b - 3 * aaa
        c4 = 1 + 3 * b + aaa + 3 * aa
        
        E1 = Price(LB)
        E2 = Price(LB)
        E3 = Price(LB)
        E4 = Price(LB)
        E5 = Price(LB)
        E6 = Price(LB)
        
        If Period > 0 Then
            For ctr = LB To ub
                If Period <> OldPeriod Then
                    XAlpha = (2 / (Period + 1))
                    XBeta = 1 - XAlpha
                    OldPeriod = Period
                End If
                
                E1 = E1 * XBeta + Price(ctr) * XAlpha
                E2 = E2 * XBeta + E1 * XAlpha
                E3 = E3 * XBeta + E2 * XAlpha
                E4 = E4 * XBeta + E3 * XAlpha
                E5 = E5 * XBeta + E4 * XAlpha
                E6 = E6 * XBeta + E5 * XAlpha
                Indicator(ctr) = c1 * E6 + c2 * E5 + c3 * E4 + c4 * E3
            Next ctr
        End If
    
    End Function
     
  7. Great! I'll get on the VB code right away...

    I'll compare T3Avergage & Ehler's optimized (SMA) RSI and post my findings here.

    Ehler's Optimized RSI method can be find on Oct issue of TA of stocks and commodities.
     
  8. pbeattie

    pbeattie