Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Gold Customer
Joined: 10/7/2004 Posts: 20
|
Hi,
What is the real code for Spearman indicator, as described in "Stocks and Commodities"?
thanks.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You should be able to add the Spearman Indicator by selecting Add Indicator/Condition to Chart | Spearman Indicator. You can view the RealCode by right-clicking on the Indicator and selecting Edit RealCode. That said, the RealCode follows:
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.1 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Spearman Indicator
'|******************************************************************
'# Cumulative
'# Period = UserInput.Integer = 10
Static movingValues As New List(Of Single)
Dim sorted(period -1) As Single
Static Avg As Single
If isFirstBar Then
movingValues.clear
Avg = (Period / 2) * (Period - 1) / Period
End If
If currentindex < period - 1 Then
movingvalues.add(price.close)
Plot = Single.NaN
Else
movingvalues.add(price.close)
sorted = movingValues.toArray
Array.sort(sorted)
Dim rank(period -1) As Single
Dim j As Integer = 0
While j < period - 1
If sorted(j) <> sorted(j + 1) Then
rank(j) = j
Else
Dim k As Integer = j + 1
Dim Sum As Single = j
While k < Period AndAlso sorted(j) = sorted(k )
Sum += k
k += 1
End While
rank(j) = Sum / (k - j)
j = k
End If
j += 1
End While
If j = period - 1 Then rank(j) = j
sorted = movingValues.toArray
Array.Sort(sorted, rank)
Dim Sums(2) As Single
For i As Integer = 0 To movingvalues.count - 1
Sums(0) += (i - Avg) * (rank(i) - Avg)
Sums(1) += (i - Avg) ^ 2
Sums(2) += (rank(i) - Avg) ^ 2
Next
plot = 100 * Sums(0) / ((Sums(1) * Sums(2)) ^ .5)
movingvalues.removeat(0)
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Gold Customer
Joined: 10/7/2004 Posts: 20
|
Thanks so much for yuor timely help. I am actually late to acknowledge your advice.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Gold Customer
Joined: 10/7/2004 Posts: 20
|
Hi, Bruce,
There appear to be a few error messages when the above Realcode is applied, wondering this could be that I am using Version 4.0.
Line 1: "If, "Elself, "Else", 'End If', or 'Const' expected
Line 3: Type "List" is not defined
Line 16: Name "Array" is not declared
Line 36: Name "Array" is not declared
Line 47: Syntax error
Thanks very much.
sara
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I'm not a programmer, but it does appear to be a result of using SF4 instead of the current version of StockFinder. Please try the following instead:
'# Cumulative
'# Period = UserInput.Integer = 10
Static movingValues As New System.Collections.Generic.List(Of Single)
Dim sorted(period -1) As Single
Static Avg As Single
If isFirstBar Then
movingValues.clear
Avg = (Period / 2) * (Period - 1) / Period
End If
If currentindex < period - 1 Then
movingvalues.add(price.close)
Plot = Single.NaN
Else
movingvalues.add(price.close)
sorted = movingValues.toArray
System.Array.sort(sorted)
Dim rank(period -1) As Single
Dim j As Integer = 0
While j < period - 1
If sorted(j) <> sorted(j + 1) Then
rank(j) = j
Else
Dim k As Integer = j + 1
Dim Sum As Single = j
While k < Period AndAlso sorted(j) = sorted(k )
Sum += k
k += 1
End While
rank(j) = Sum / (k - j)
j = k
End If
j += 1
End While
If j = period - 1 Then rank(j) = j
sorted = movingValues.toArray
System.Array.Sort(sorted, rank)
Dim Sums(2) As Single
For i As Integer = 0 To movingvalues.count - 1
Sums(0) += (i - Avg) * (rank(i) - Avg)
Sums(1) += (i - Avg) ^ 2
Sums(2) += (rank(i) - Avg) ^ 2
Next
plot = 100 * Sums(0) / ((Sums(1) * Sums(2)) ^ .5)
movingvalues.removeat(0)
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Gold Customer
Joined: 10/7/2004 Posts: 20
|
Dear Bruce,
Thanks so much for spending time and effort to work on the problem. Your new formula works very well.
Again, so sorry for being late to acknowledge your help.
sara
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |