Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

My Realcode does not function properly Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
papere
Posted : Monday, November 12, 2012 10:50:29 PM
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
 
Bruce_L
Posted : Tuesday, November 13, 2012 7:23:57 AM


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
papere
Posted : Tuesday, November 13, 2012 10:02:44 AM
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.  

Bruce_L
Posted : Tuesday, November 13, 2012 10:05:23 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.