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 |

5 closing lows in a row Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
bironique
Posted : Sunday, May 24, 2009 8:48:51 AM
Registered User
Joined: 2/10/2009
Posts: 15
How can I find stocks that have been making 5 closing lows in a row? André
garypayne
Posted : Sunday, May 24, 2009 10:52:47 PM
Registered User
Joined: 6/24/2006
Posts: 122
Try  This

If Price.Last < Price.Last(1) AndAlso _
 Price.Last(1) < Price.Last(2) AndAlso _
 Price.Last(2) < Price.Last(3) AndAlso _
 Price.Last(3) < Price.Last(4) AndAlso _
 Price.Last(4) < Price.Last(5) Then Pass
bobre1
Posted : Monday, May 25, 2009 10:13:12 AM
Registered User
Joined: 10/7/2004
Posts: 886

The code can be generalized by writing it as follows:

'# bars=UserInput.Integer = 5
Dim x As Integer

For x = 0 To (bars - 1)
 If price.last(x) < price.last(x + 1) Then
  pass
 Else
  fail
  Exit For 
 End If
Next x

Bruce_L
Posted : Tuesday, May 26, 2009 9:38:37 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
bironique,
I'm not sure what you mean for sure by "closing lows", but if the Price.Last < Price.Last(1) guess by garypayne and bobre1 is correct, another generalized solution that avoids the use of a loop at each bar might be:

'# BarsInRow = UserInput.Integer = 5
Static Count As Integer
Static PlusOne As Integer
If CurrentIndex >= 1 Then
    If Price.Last < Price.Last(1) Then
        Count += 1
    End If
Else
    Count = 0
    PlusOne = BarsInRow + 1
End If
If CurrentIndex >= PlusOne Then
    If Price.Last(BarsInRow) < Price.Last(PlusOne) Then
        Count -= 1
    End If
End If
If CurrentIndex >= BarsInRow Then
    If Count = BarsInRow Then
        Pass
    End If
Else
    SetIndexInvalid
End If

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bironique
Posted : Wednesday, May 27, 2009 7:45:51 PM
Registered User
Joined: 2/10/2009
Posts: 15
Thanks!!!
bironique
Posted : Wednesday, May 27, 2009 7:49:01 PM
Registered User
Joined: 2/10/2009
Posts: 15
Bruce,
If I also want to use it with the Wilder's RSI, what would be the code I'll have to use instead of «Price»?
André
Bruce_L
Posted : Thursday, May 28, 2009 9:34:25 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
bironique,
I would probably use a slightly different approach with Wilder's RSI. Dragging and Dropping the Indicator into the Class tab of the RealCode Editor should create something similar to the following line:

        '# WR = indicator.WildersRSI

Which is just one line of the following RealCode which would need to replace everything below the Inherits line in the Class tab of a RealCode Rule:

    Sub New
        AutoLoop = False
        '# WR = indicator.WildersRSI
        '# BarsInRow = UserInput.Integer = 5
    End Sub
    Public Overrides Sub CallUserCode()
        Dim Count As Integer = 0
        Dim PlusOne As Integer = BarsInRow + 1
        If WR.Line.Count >= PlusOne Then
            For i As Integer = 1 To BarsInRow
                If WR.Line.Value(i) < WR.Line.Value(i - 1) Then
                    Count += 1
                End If
            Next
            If Count = BarsInRow Then
                AddToOutput(WR.Line.DateValue(BarsInRow), True)
            Else
                AddToOutput(WR.Line.DateValue(BarsInRow), False)
            End If
            If WR.Line.Count > PlusOne Then
                For i As Integer = PlusOne To WR.Line.Count - 1
                    If WR.Line.Value(i) < WR.Line.Value(i - 1) Then
                        Count += 1
                    End If
                    If WR.Line.Value(i - BarsInRow) < WR.Line.Value(i - PlusOne) Then
                        Count -= 1
                    End If
                    If Count = BarsInRow Then
                        AddToOutput(WR.Line.DateValue(i), True)
                    Else
                        AddToOutput(WR.Line.DateValue(i), False)
                    End If
                Next
            End If
        End If
    End Sub
End Class

WR is a variable created by Dragging and Dropping the Wilder's RSI into the RealCode Editor. You might notice that this variable is used instead of Price throughout the rest of the RealCode. Dragging and Dropping a different Indicator into the RealCode would create a different variable with a different name that would need to be used throughout the rest of the RealCode.

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