Registered User Joined: 2/26/2005 Posts: 115
|
I would appreciate the help of a trainer that knows the SF v. 4 tricks in creating a formula for the following simple idea:
1."T" threshold (should be selectable and changeable): e.g. 2%
2. c/c1-1 (or an 1-period ROC of closing prices expressed as decimals, e.g. 2% as 0.02)
3. for every day in the past over a selectable and changeable lookback period "L" compute( #2 - #1)
4. compute over the entire lookback period L the sum of all #3 as long as #3<=0
5. compute over the entire lookback period L the sum of all #3 as long as #3>0
6. compute (#4 / - #5) note: there is a minus before #5
In other words, over a lookback period L devide the sum of all daily returns that are each equal or less than the specified threshold value (#1) by the negative (i.e. multiplied by -1) sum of all dailiy returns that are greater than the specified threshold value (#1).
Thanks
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
A RealCode Indicator for a literal interpretation of your request would seem to be:
'# Threshold = UserInput.Single = 2
'# Lookback = UserInput.Integer = 20
Static Sum(1) As Single
Static T As Single
If isFirstBar Then
Sum(0) = 0
Sum(1) = 0
T = Threshold / 100
Else
Dim ROCmT As Single = Price.Last / Price.Last(1) - 1 - T
If ROCmT <= 0 Then
Sum(0) += ROCmT
Else
Sum(1) -= ROCmT
End If
End If
If CurrentIndex > Lookback Then
Dim ROCmT As Single = Price.Last(Lookback) / _
Price.Last(LookBack + 1) - 1 - T
If ROCmT <= 0 Then
Sum(0) -= ROCmT
Else
Sum(1) += ROCmT
End If
End If
If CurrentIndex >= Lookback AndAlso _
Sum(1) <> 0 Then
Plot = Sum(0) / Sum(1)
Else
Plot = Single.NaN
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
Registered User Joined: 2/26/2005 Posts: 115
|
Hey Bruce, thanks for your help! I think we are getting close, but it looks like the execution of the formula I describe when done in Excel (with price inputs from StockFinder 4) vs. the formula you built give different results and so I will contact the customer service to send you my spreadsheet for you to see what the difference is--quite possibly the description I gave you is off. Stay tuned...
I appreciate it.
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Your description and your spreadsheet have #4 and #5 reversed in line 6.
'# Threshold = UserInput.Single = 1
'# Lookback = UserInput.Integer = 252
Static Sum(1) As Single
Static T As Single
If isFirstBar Then
Sum(0) = 0
Sum(1) = 0
T = Threshold / 100
Else
Dim ROCmT As Single = Price.Last / Price.Last(1) - 1 - T
If ROCmT <= 0 Then
Sum(0) -= ROCmT
Else
Sum(1) += ROCmT
End If
End If
If CurrentIndex > Lookback Then
Dim ROCmT As Single = Price.Last(Lookback) / _
Price.Last(LookBack + 1) - 1 - T
If ROCmT <= 0 Then
Sum(0) += ROCmT
Else
Sum(1) -= ROCmT
End If
End If
If CurrentIndex >= Lookback AndAlso _
Sum(0) <> 0 Then
Plot = Sum(1) / Sum(0)
Else
Plot = Single.NaN
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|