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 |

Spearman Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
sara
Posted : Saturday, February 12, 2011 6:42:35 PM
Gold Customer Gold Customer

Joined: 10/7/2004
Posts: 20
Hi,
What is the real code for Spearman indicator, as described in "Stocks and Commodities"?
thanks.
Bruce_L
Posted : Monday, February 14, 2011 9:30:41 AM


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
sara
Posted : Thursday, February 17, 2011 1:21:29 AM
Gold Customer Gold Customer

Joined: 10/7/2004
Posts: 20
Thanks so much for yuor timely help. I am actually late to acknowledge your advice.
Bruce_L
Posted : Thursday, February 17, 2011 8:14:53 AM


Worden Trainer

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

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
sara
Posted : Sunday, February 20, 2011 9:41:22 AM
Gold Customer 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

Bruce_L
Posted : Monday, February 21, 2011 2:02:08 PM


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
sara
Posted : Saturday, March 5, 2011 9:44:41 AM
Gold Customer 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
Bruce_L
Posted : Monday, March 7, 2011 7:52:51 AM


Worden Trainer

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

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