Registered User Joined: 3/31/2005 Posts: 37
|
I am trying to filter a list to find stocks that today's range falls within yesterday's range and that the range for today is less than half of what it was yesterday. When I view the results, some of the stocks fall beyond yesterday's range. Can someone please point me in the right direction? Thank you.
Static day1, day2, half As Single
day1 = price.High - price.low 'range of first day
day2 = price.high(1) - price.Low(1) 'range of previous day
' if the first day's high is lower than the second day's high and
' the first days low is higher than the second days low
' then divide the range of the second day in half.
If price.High <= price.High(1) And price.Low >= price.Low(1) Then
half = day2 / 2
End If
' if the range of the first day is less than half the range of the second day then pass
If day1 <= half Then
Pass
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Your test is for day1 being less than or equal to half, but half is only being given a value when the current bar is entirely contained within the range of the previous bar. Since half is static, it retains its value and you are still checking for day1 <= half even when the current bar is not entirely contained with the range of the previous bar.
A RealCode Condition which both changes static to dim and only test if day1 <= half when price.High <= price.High(1) And price.Low >= price.Low(1) could be written as:
Dim day1 As Single = price.High - price.low 'range of first day
Dim day2 As Single = price.high(1) - price.Low(1) 'range of previous day
' if the first day's high is lower than the second day's high and
' the first days low is higher than the second days low
' then divide the range of the second day in half.
If Price.High <= Price.High(1) AndAlso Price.Low >= Price.Low(1) Then
Dim half As Single = day2 / 2
' if the range of the first day is less than half the range of the second day then pass
If day1 <= half Then
Pass
End If
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
Registered User Joined: 3/31/2005 Posts: 37
|
It obviously helps to know what you are doing. I really appreciate your assistance. Thank you very much.
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|