Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
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.
|
|
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.
|
|
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
|
|
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 ?
|
|
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?
|
|
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
|
|
Registered User Joined: 7/30/2008 Posts: 30
|
thank you for ETFs and clarifcations. I will try to use both approaches.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
saswordlwide,
You're welcome. Our pleasure.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |