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 |

trailing % change Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
sasworldwide
Posted : Friday, March 27, 2009 4:00:03 PM
Registered User
Joined: 7/30/2008
Posts: 30
could you please help me with the real code in SF to do the following. 

Task 1.
Input - number of bars. let us say 50 bars. I want to keep changing this number.
Calculate the % difference from the closing of 50 bars ago, i.e. 50 bars ago is 0% and then it goes to up or down in % of the stock price. Let us call it "%change of stock". 
I will need to have a graph over the last 50 bars for "%change of stock"

Task 2. 
Input - number of bars. let us say 50 bars. I want to keep changing this number. 
Input - symbol of an Index such as S&P, Dow, etc.
Calculate the difference between "%change of stock" and "%change of Index". let us call it "relative change"
I will need to have a graph over the last 50 bars for "relative change".

Thank you.
StockGuy
Posted : Friday, March 27, 2009 4:34:07 PM

Administration

Joined: 9/30/2004
Posts: 9,187
Task1

Just add Price Rate of Change (Net) to your chart and set the Period to 50.

Task 2

Add Price for Symbol to your chart and set the symbol to DJ-30, SP-500, etc.
Add Rate of Change (Net) of Indicator and choose the price plot you just added and set the period to 50.
Now, drag Price Rate of Change plot from Task 1 onto the Rate of Change plot from Task 2 and click Create Indicator > Difference.

This will plot the line you're looking for.   You can "pin" the rate of change indicators if you want to free up some screen real estate.
Bruce_L
Posted : Friday, March 27, 2009 5:03:35 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
saswordlwide,
StockGuy's interpretation was my first thought and is probably what you want, but if it isn't, you might want to try the following RealCode Indicator for Task 1:

'# Period = UserInput.Integer = 50
Static Basis As Single
Static Start As Integer
If isFirstBar Then
    Start = Price.Count - Period - 1
    Basis = Single.NaN
End If
If CurrentIndex = Start Then
    Basis = Price.Last / 100
End If
Plot = Price.Last / Basis - 100

If that's correct, then you should be able to add a Price for Symbol Indicator as described by StockGuy and Drag and Drop it into the RealCode Editor to create something similar to the first line of the following RealCode Indicator for Task 2:

'# PfS = indicator.PriceforSymbol
'# Period = UserInput.Integer = 50
Static Basis(1) As Single
Static Start As Integer
If isFirstBar Then
    Start = Price.Count - Period - 1
    Basis(0) = Single.NaN
    Basis(1) = Single.NaN
End If
If CurrentIndex = Start Then
    Basis(0) = Price.Last / 100
    Basis(1) = PfS.Last / 100
End If
Plot = Price.Last / Basis(0) - PfS.Last / Basis(1)

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
sasworldwide
Posted : Friday, March 27, 2009 5:24:13 PM
Registered User
Joined: 7/30/2008
Posts: 30
Great. thank you.  it worked. Can you help me to find the list of all existing ETFs ?
sasworldwide
Posted : Friday, March 27, 2009 5:33:26 PM
Registered User
Joined: 7/30/2008
Posts: 30

I will have to check out the diffrence in the results for two appraoches. According to the first recommendation, I used Price Rate of Change (Percent) and Rate of Change (Percent) for the indicator. I then substracted the two. 

What is the difference in these two approaches Bruce L and StockGuy?

Bruce_L
Posted : Friday, March 27, 2009 8:22:48 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
saswordlwide,
There is a Watchlist in the Component section called Exchange Traded Funds.

If you are using Rate of Change (Percent) instead of Rate of Change (Net), the last value displayed using both methods should match. The big difference is that StockGuy's approach shows a running Rate of Change starting Period Bars from the beginning of the data while my approach doesn't start plotting until Period Bars ago and starts at 0%.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
sasworldwide
Posted : Sunday, March 29, 2009 10:16:34 PM
Registered User
Joined: 7/30/2008
Posts: 30
thank you for ETFs and clarifcations. I will try to use both approaches.
Bruce_L
Posted : Monday, March 30, 2009 9:13:43 AM


Worden Trainer

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

-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.