| Welcome Guest, please  sign in  to participate in a discussion. | Search | 	Active Topics | | 
	
	
	| Registered User Joined: 10/7/2004
 Posts: 23
 
 | I need help to write a Realcode rule to find a two day low reversal. Criteria 1) price just did a two day low on the daily chart. 2) On the hourly chart in realtime, price moving up making a new high, taking out the last completed hourly-high candle. | 
	|  | 
	
	
	|  
  Worden Trainer
 
 Joined: 10/7/2004
 Posts: 65,138
 
 | I'm not sure I'm correctly interpreting your intended meanings for "just did a two day low on the daily chart" and "taking out the last completed hourly-high candle", but you may want to try the following RealCode Rule on a 1-Hour Chart. We can help you modify it with additional clarification from you if it does not meet your needs. 
 Static DayLow(1) As Single
 Static TwoDayLow As Boolean
 Static DayCount As Integer
 If isFirstBar Then
 DayLow(1) = Single.NaN
 DayLow(0) = Single.NaN
 TwoDayLow = False
 DayCount = 0
 Else If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
 DayLow(1) = System.Math.Min(Price.Low, DayLow(0))
 DayLow(0) = Price.Low
 DayCount += 1
 End If
 DayLow(1) = System.Math.Min(Price.Low, DayLow(1))
 DayLow(0) = System.Math.Min(Price.Low, DayLow(0))
 If DayCount >= 2 Then
 If TwoDayLow = True AndAlso _
 Price.High > Price.High(1) Then
 Pass
 End If
 Else
 SetIndexInvalid
 End If
 If DayLow(1) = Price.Low Then
 TwoDayLow = True
 Else
 TwoDayLow = False
 End If
 
 -Bruce
 Personal Criteria Formulas
 TC2000 Support Articles
 | 
	|  | 
	
	
	| Registered User Joined: 10/7/2004
 Posts: 23
 
 | Bruce, I want todays candle to have made a new low, then the hourly candle to make a new high in real-time. If you look at the symbol KG, it made a new two day low today. On the hourly chart I want the Realcode to trigger when price moved up making a new 2 bar (hourly) high in realtime. On the symbol KG it would have triggered at 11.43. | 
	|  | 
	
	
	|  
  Worden Trainer
 
 Joined: 10/7/2004
 Posts: 65,138
 
 | So you need the Rule to be for a 1-Minute Chart instead of a 1-Hour Chart? A RealCode Rule that just returns True whenever it is a 2-Day Low and a 2-Hour High would return True for KG before 11:43 AM ET on December 9, 2009 (and wouldn't actually be True at that point in the day). 
 Static DayLow(1) As Single
 Static HourHigh(1) As Single
 Static TwoDayLow As Boolean
 Static TwoHourHigh As Boolean
 Static DayCount As Integer
 If isFirstBar Then
 DayLow(1) = Single.NaN
 DayLow(0) = Single.NaN
 HourHigh(1) = Single.NaN
 HourHigh(0) = Single.NaN
 TwoDayLow = False
 TwoHourHigh = False
 DayCount = 0
 Else If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
 DayLow(1) = DayLow(0)
 DayLow(0) = Price.Low
 HourHigh(1) = System.Math.Max(Price.High, HourHigh(0))
 HourHigh(0) = Price.High
 TwoDayLow = False
 TwoHourHigh = False
 DayCount += 1
 Else If Price.DateValue.Hour <> Price.DateValue(1).Hour Then
 HourHigh(1) = HourHigh(0)
 HourHigh(0) = Price.High
 TwoHourHigh = False
 End If
 DayLow(0) = System.Math.Min(Price.Low, DayLow(0))
 If Price.Low < DayLow(1) Then
 DayLow(1) = Price.Low
 TwoDayLow = True
 End If
 HourHigh(0) = System.Math.Max(Price.High, HourHigh(0))
 If Price.High > HourHigh(1) Then
 HourHigh(1) = Price.High
 TwoHourHigh = True
 End If
 If DayCount >= 2 Then
 If TwoDayLow = True AndAlso _
 TwoHourHigh = True Then
 Pass
 End If
 Else
 SetIndexInvalid
 End If
 
 -Bruce
 Personal Criteria Formulas
 TC2000 Support Articles
 | 
	|  | 
	
	
	| Registered User Joined: 10/7/2004
 Posts: 23
 
 | Bruce,Firstly, thanks for your help. The first Realcode rule is almost perfect. The only change I would ask you to make is for todays low to be lower (a must) than yesterdays low. I'm using this on the 1- hour chart. | 
	|  | 
	
	
	|  
  Worden Trainer
 
 Joined: 10/7/2004
 Posts: 65,138
 
 | Please see if this works better for you: 
 Static DayLow(1) As Single
 Static TwoDayLow As Boolean
 Static DayCount As Integer
 If isFirstBar Then
 DayLow(1) = Single.NaN
 DayLow(0) = Single.NaN
 TwoDayLow = False
 DayCount = 0
 Else If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
 DayLow(1) = DayLow(0)
 DayLow(0) = Price.Low
 TwoDayLow = False
 DayCount += 1
 End If
 If DayCount >= 2 Then
 If TwoDayLow = True AndAlso _
 Price.High > Price.High(1) Then
 Pass
 End If
 Else
 SetIndexInvalid
 End If
 DayLow(0) = System.Math.Min(Price.Low, DayLow(0))
 If Price.Low < DayLow(1) Then
 DayLow(1) = Price.Low
 TwoDayLow = True
 Else
 TwoDayLow = False
 End If
 
 -Bruce
 Personal Criteria Formulas
 TC2000 Support Articles
 | 
	|  | 
	
	
	| Registered User Joined: 10/7/2004
 Posts: 23
 
 | Bruce, that last Realcode works perfect, thanks.Would it be possible to modify that last Realcode to trigger when price has crossed up through the hourly 8exp moving average. Example 1The stock ICA, made a new low (lower than the day before daily candle), then when price crossed up through the 8exp on the 1-hour chart to trigger.  ICA should have triggered on the second last hour of the day. Example 2On SFL it made a new lower low (lower than the day before daily candle), it wasn't till the last hour when it would have triggered as it crossed up through the 8 exp on the 1 - hour chart. | 
	|  | 
	
	
	|  
  Worden Trainer
 
 Joined: 10/7/2004
 Posts: 65,138
 
 | If you Drag and Drop the Moving Average into the Code tab of the RealCode Editor, it should create something similar to the first line of the following RealCode Rule: 
 '# MA = indicator.MovingAverage
 Static DayLow(1) As Single
 Static TwoDayLow As Boolean
 Static DayCount As Integer
 If isFirstBar Then
 DayLow(1) = Single.NaN
 DayLow(0) = Single.NaN
 TwoDayLow = False
 DayCount = 0
 Else If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
 DayLow(1) = DayLow(0)
 DayLow(0) = Price.Low
 TwoDayLow = False
 DayCount += 1
 End If
 If DayCount >= 2 Then
 If TwoDayLow = True AndAlso _
 Price.Last > MA.Value AndAlso _
 Price.Last(1) <= MA.Value(1) Then
 Pass
 End If
 Else
 SetIndexInvalid
 End If
 DayLow(0) = System.Math.Min(Price.Low, DayLow(0))
 If Price.Low < DayLow(1) Then
 DayLow(1) = Price.Low
 TwoDayLow = True
 End If
 
 -Bruce
 Personal Criteria Formulas
 TC2000 Support Articles
 | 
	|  | 
	
	
	| Registered User Joined: 10/7/2004
 Posts: 23
 
 | Thanks for all you help Bruce. | 
	|  | 
	
	
	|  
  Worden Trainer
 
 Joined: 10/7/2004
 Posts: 65,138
 
 | You're welcome. 
 -Bruce
 Personal Criteria Formulas
 TC2000 Support Articles
 | 
	|  | 
| Guest-1 |