Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 2/28/2005 Posts: 36
|
I would like to figure out how to create an indicator or condition which will show price as a perentage above or below a certain price based on a date in the past. In other words, I would like to be able to scan a list with the output being each stocks relative position to its price at some prior date. For example, stock X has a price (either OHLC) on July 10th. How is stock X's price today, relative to its price on July 10th? Price in Range (PIR) doesn't quite get it, because if price exceeds July 10ths price and retraces, but is still above the July 10 price, the PIR result is less than 100%. Min or Max of Line plots the line from a certain number of bars ago, but I don't see how to calculate variance above of below the line in present time.
Thanks,
Bob M
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You could try something similar to the following RealCode Indicator:
RealCode for Real People: Indicators
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Price Percent Change from Date
'|******************************************************************
'# Cumulative
'# Basis = UserInput.Date = "7/9/2010"
Static Ref As Single
If isFirstBar Then
Ref = IndexForDate(Basis)
End If
OpenValue = 100 * (Price.Open / Price.Bar.Value(Ref) - 1)
HighValue = 100 * (Price.High / Price.Bar.Value(Ref) - 1)
LowValue = 100 * (Price.Low / Price.Bar.Value(Ref) - 1)
Plot = 100 * (Price.Last / Price.Bar.Value(Ref) - 1)
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 9/30/2006 Posts: 317
|
Bruce,
Can this indicator be modified so rather than manually editing the date, it is based on the first date on the chart? (both daily and for minute charts)
Thanks
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Designer,
Sure, but it won't work as a WatchList Column (because the context won't be the Chart):
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Price Percent Change from Chart Start
'|******************************************************************
'#RECALC_ON_ZOOM_SCROLL
Static Ref As Single
If isFirstBar Then
Ref = IndexForDate(ActiveChart.ZoomStartDate)
End If
OpenValue = 100 * (Price.Open / Price.Bar.Value(Ref) - 1)
HighValue = 100 * (Price.High / Price.Bar.Value(Ref) - 1)
LowValue = 100 * (Price.Low / Price.Bar.Value(Ref) - 1)
Plot = 100 * (Price.Last / Price.Bar.Value(Ref) - 1)
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 3/5/2010 Posts: 9
|
Bruce,What code change is needed to make the calculations based on the last price in the activechart.zoomenddate, not "price.last".Thanks
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Keeping in mind that it still won't work as a WatchList Column (and for the same reasons), you could just stop Plotting after the ZoomEndDate (although this would not visibly change the Indicator):
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Price Percent Change for Chart
'|******************************************************************
'#RECALC_ON_ZOOM_SCROLL
Static Ref As Single
If isFirstBar Then
Ref = IndexForDate(ActiveChart.ZoomStartDate)
End If
If Price.DateValue <= ActiveChart.ZoomEndDate Then
OpenValue = 100 * (Price.Open / Price.Bar.Value(Ref) - 1)
HighValue = 100 * (Price.High / Price.Bar.Value(Ref) - 1)
LowValue = 100 * (Price.Low / Price.Bar.Value(Ref) - 1)
Plot = 100 * (Price.Last / Price.Bar.Value(Ref) - 1)
Else
OpenValue = Single.NaN
HighValue = Single.NaN
LowValue = Single.NaN
Plot = Single.NaN
End If
Or just Plot the same Value for all Bars:
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Price Percent Change for Chart
'|******************************************************************
'#RECALC_ON_ZOOM_SCROLL
Static Ref(1) As Integer
Static Bar(3) As Single
If isFirstBar Then
Ref(0) = IndexForDate(ActiveChart.ZoomStartDate)
Ref(1) = IndexForDate(ActiveChart.ZoomEndDate)
Bar(0) = 100 * (Price.Bar.OpenValue(Ref(1)) / Price.Bar.Value(Ref(0)) - 1)
Bar(1) = 100 * (Price.Bar.HighValue(Ref(1)) / Price.Bar.Value(Ref(0)) - 1)
Bar(2) = 100 * (Price.Bar.LowValue(Ref(1)) / Price.Bar.Value(Ref(0)) - 1)
Bar(3) = 100 * (Price.Bar.Value(Ref(1)) / Price.Bar.Value(Ref(0)) - 1)
End If
OpenValue = Bar(0)
HighValue = Bar(1)
LowValue = Bar(2)
Plot = Bar(3)
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 3/5/2010 Posts: 9
|
Bruce,You do enhance the value of Stock Finder!Thanks.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |