Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Price change from point in time Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
BobM
Posted : Tuesday, November 9, 2010 9:01:44 PM
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
Bruce_L
Posted : Wednesday, November 10, 2010 9:19:00 AM


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
Designer
Posted : Friday, January 7, 2011 10:42:07 AM
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
Bruce_L
Posted : Friday, January 7, 2011 10:50:31 AM


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
dslaby
Posted : Saturday, January 8, 2011 9:52:18 PM
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
Bruce_L
Posted : Monday, January 10, 2011 1:04:38 PM


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
dslaby
Posted : Monday, January 10, 2011 2:02:32 PM
Registered User
Joined: 3/5/2010
Posts: 9
Bruce,You do enhance the value of Stock Finder!Thanks.
Bruce_L
Posted : Monday, January 10, 2011 2:03:09 PM


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.