Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 2/10/2009 Posts: 15
|
How can I find stocks that have been making 5 closing lows in a row? André
|
|
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
|
|
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
|
|

 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
|
|
Registered User Joined: 2/10/2009 Posts: 15
|
Thanks!!!
|
|
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é
|
|

 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
|
|
Guest-1 |