Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
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?
|
|
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.
|
|
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
|
|
Gold Customer
Joined: 5/3/2010 Posts: 86
|
It puts some emoticons on forumals :(
|
|
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
|
|
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
|
|
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
|
|
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?
|
|
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
|
|
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
|
|
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
|
|
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
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |