Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

RSI Solver? Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
Putt4Doughs
Posted : Monday, July 12, 2010 3:39:34 PM

Registered User
Joined: 11/1/2009
Posts: 80

I know that calculating a Relative Strength Indicator (RSI) given a price history is easy, but ...

I'm looking to do the opposite, that is, given a target RSI level (30, 70, etc.), I'd like to know what price (specifically what closing price) would be necessary to reach that RSI level.

For example, taking Wilder's RSI(14) period default as an example, I'd like to be able to calculate what closing price for a symbol would be necessary to hit an RSI value of, say, 70. Or 30. Or whatever.

Being able to adjust both the period and the RSI level would make this very useful.

Any thoughts?

Putt4Doughs
Posted : Monday, July 12, 2010 3:48:37 PM

Registered User
Joined: 11/1/2009
Posts: 80
Here's another way of saying what I'm looking for ...

Many trader tools will calculate RSI(x) for a given stock price history, but I'm looking for a tool that begins with RSI(x) levels and returns the closing price needed to reach that level.

An AAPL Example:

      Target close price at level:
     
      Close    RSI(2)   20       25       30       70       75       80
AAPL  $259.62  86.63  $251.43  $253.56  $254.98  $259.04  $259.24  $259.42


Note: Computations reflect the 07/09/2010 closing price.
anindya_chak
Posted : Monday, July 12, 2010 8:51:57 PM
Gold Customer Gold Customer

Joined: 5/3/2010
Posts: 86
Doing it 1 bar forward should not be too difficult...

RSI(t)  = 100*(1-1/(1+Avg Gain(t-p)/Avg Loss(t-p)))

Since p is the same the ratio

RS = Sum(Gains over last p)/Sum ( of Losses over last p)

So RS (t+1) = Sum(Gains over last p-1) - Indicator(G/L)*Gain(p) + Forecast( Ind(G/L)*Gain(t+1) /
                         Sum(Losses over last p-1) - Indicator(G/L)*Losses(p) + Forecast( Ind(G/L)*Losses(t+1)

or something like that.

So you can do 2 scenarios having inputs on the Gain/Loss +1 and the RS will compute itself......just need to have the running totals
anindya_chak
Posted : Monday, July 12, 2010 8:52:48 PM
Gold Customer Gold Customer

Joined: 5/3/2010
Posts: 86
It puts some emoticons on forumals :(
Bruce_L
Posted : Tuesday, July 13, 2010 9:48:38 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
It probably won't be accurate "near the beginning" of the Plot, but you may wish to try the following:

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:RSI Solver
'|******************************************************************
'# TargetRSI = UserInput.Single = 50
'# Period = UserInput.Single = 14
'# Cumulative
Static sumWeight As Single
Static termRatio As Single
Static weight As Single
Static Num As Single
Static Den As Single
Static RSI As Single
If 0 < TargetRSI AndAlso TargetRSI < 100 AndAlso 1 < Period Then
    If isFirstBar Then
        sumWeight = 1
        termRatio = (Period - 1) / Period
        weight = 1 / sumWeight
        Num = 0
        Den = 0
        RSI = Single.NaN
    Else
        Num = Num * (1 - Weight) + Weight * System.Math.Max(0, Price.Last - Price.Last(1))
        Den = Den * (1 - Weight) + Weight * System.Math.Abs(Price.Last - Price.Last(1))
        sumWeight = sumWeight * termRatio + 1
        weight = 1 / sumWeight
        If Den > 0 Then
            RSI = 100 * Num / Den
        Else
            RSI = 50
        End If
    End If
    If TargetRSI > RSI Then
        Plot = Price.Last + (TargetRSI * (Period - 1) * Den - 100 * (Period - 1) * Num) / (100 - TargetRSI)
    Else If TargetRSI < RSI Then
        Plot = Price.Last - (100 * (Period - 1) * Num / TargetRSI - (Period - 1) * Den)
    Else If TargetRSI = RSI Then
        Plot = Price.Last
    Else
        Plot = Single.NaN
    End If
Else
    Plot = Single.NaN
End If

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Putt4Doughs
Posted : Tuesday, July 13, 2010 11:02:37 AM

Registered User
Joined: 11/1/2009
Posts: 80
Bruce, thanks!

I actually use fewer than 14 periods for my RSI, so the accuracy "near the beginning" of the plot won't be as big an issue. I'll go ahead and change that variable.

I probably won't get to try this until the weekend, but I appreciate the RealCode - you've saved me several hours of time.

... Bill
Bruce_L
Posted : Tuesday, July 13, 2010 11:05:47 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You're right. The shorter the period, the closer to the beginning you can get and still get useful results.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Mike From Philly
Posted : Thursday, December 30, 2010 7:18:32 PM
Registered User
Joined: 9/18/2009
Posts: 60
Bruce, this is awesome.   I works perfect.  I double checked the numbers with TradingMarket's RSI calculator and it matched.

Can I ask for a slight modification?   Is it possible to adjust the program to print a marker (line, arrow, etc.) on the main price chart at the most recent price calculated with the solver?  
Bruce_L
Posted : Friday, December 31, 2010 9:35:39 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
Mike From Philly,
If you Drag and Drop the RealCode Indicator to Price History (the Price itself, not just the Pane) and select Overlay with Price History, it will Plot it in the same Pane and Scale as Price History.

If you want something beyond this, I'm not quite understanding the request.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Mike From Philly
Posted : Monday, January 3, 2011 7:54:14 PM
Registered User
Joined: 9/18/2009
Posts: 60
My goal is to have a little line beneath the most recent bar at the price which is computed by the Solver.   Here is an example.  The yellow bar is the RSI Solver output.

http://screencast.com/t/AvbSKMsA
Bruce_L
Posted : Tuesday, January 4, 2011 8:55:02 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You could try Plotting the following RealCode Indicator as a Shape Plot. It actually Plots the last two Bars, but the first Bar Plotted as a Shape Plot won't show for some reason, so it should do what you want.

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:RSI Solver for Last Bar Only
'|******************************************************************
'# TargetRSI = UserInput.Single = 50
'# Period = UserInput.Single = 14
'# Cumulative
Static sumWeight As Single
Static termRatio As Single
Static weight As Single
Static Num As Single
Static Den As Single
Static RSI As Single
If 0 < TargetRSI AndAlso TargetRSI < 100 AndAlso 1 < Period Then
    If isFirstBar Then
        sumWeight = 1
        termRatio = (Period - 1) / Period
        weight = 1 / sumWeight
        Num = 0
        Den = 0
        RSI = Single.NaN
    Else
        Num = Num * (1 - Weight) + Weight * System.Math.Max(0, Price.Last - Price.Last(1))
        Den = Den * (1 - Weight) + Weight * System.Math.Abs(Price.Last - Price.Last(1))
        sumWeight = sumWeight * termRatio + 1
        weight = 1 / sumWeight
        If Den > 0 Then
            RSI = 100 * Num / Den
        Else
            RSI = 50
        End If
    End If
    If CurrentIndex >= Price.Count - 2 Then
        If TargetRSI > RSI Then
            Plot = Price.Last + (TargetRSI * (Period - 1) * Den - 100 * (Period - 1) * Num) / (100 - TargetRSI)
        Else If TargetRSI < RSI Then
            Plot = Price.Last - (100 * (Period - 1) * Num / TargetRSI - (Period - 1) * Den)
        Else If TargetRSI = RSI Then
            Plot = Price.Last
        Else
            Plot = Single.NaN
        End If
    Else
        Plot = Single.NaN
    End If
Else
    Plot = Single.NaN
End If

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Mike From Philly
Posted : Thursday, January 6, 2011 9:21:19 PM
Registered User
Joined: 9/18/2009
Posts: 60
Thank you !!!   That works.   Here is what it looks like.  The gold box is the solver price

http://screencast.com/t/6opya9G7PMT
Bruce_L
Posted : Friday, January 7, 2011 8:18:37 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You're welcome.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.