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

help with indicator Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
kostas_gr
Posted : Friday, May 4, 2012 10:40:57 AM
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

Bruce_L
Posted : Friday, May 4, 2012 11:13:41 AM


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
kostas_gr
Posted : Sunday, May 6, 2012 12:01:45 PM
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.

Bruce_L
Posted : Thursday, May 10, 2012 11:25:15 AM


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