Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 8/10/2008 Posts: 30
|
Hello - I would like to create rule where everytime a candle makes a 3 period High or Low the color of the candles change until a High or Low is made in the opposite direction at which time the candle colors would change. For example, when a stock makes 3 period high all candles from that point forward will be filled in Green until such a time that a 3 period low is made and from that point forward all candles will be filled in Red until another 3 period high is made. Please advise. Thanks!
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
It seems to me from your description that there would actually be four possible states.
1 - No 3-Period High or Low has yet occurred.
2 - The last 3-Period High or Low was a High.
3 - The last 3-Period High or Low was a Low.
4 - The last 3-Period High or Low was both a High and a Low.
The following RealCode Paint Scheme takes into account all four possibilities:
Static State As Color
If CurrentIndex >= 2 Then
If Price.High >= Price.MaxHigh(2, 1) Then
If Price.Low <= Price.MinLow(2, 1) Then
State = Color.Yellow
Else
State = Color.Lime
End If
Else If Price.Low <= Price.MinLow(2, 1) Then
State = Color.Red
End If
Else
State = Color.White
End If
PlotColor = State
You can left-click on an Indicator to bring up its Edit window and select Edit (to the right of Paint Scheme) | Edit (to the right of Apply Realcode) to get to the Code tab of the RealCode Editor where the RealCode Paint Scheme would need to be Applied.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 3/20/2005 Posts: 45
|
Bruce,
I'm trying to convert this code to a rule that gives me a true condition when one of the colors is true. If there are more than two bars of the same color in a row then it will not fire correctly. Here is the code I have so far for the yellow condition:
If CurrentIndex >= 2 Then
If Price.High >= Price.MaxHigh(2, 1) AndAlso _
Price.Low <= Price.MinLow(2, 1) Then
Pass
End If
End If
Any help would be appreciated.
Thanks,
Matman
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
If you start with the original RealCode and store the State as a number instead of a Color, you can just check for the State:
Static State As Integer
If CurrentIndex >= 2 Then
If Price.High >= Price.MaxHigh(2, 1) Then
If Price.Low <= Price.MinLow(2, 1) Then
State = 4
Else
State = 2
End If
Else If Price.Low <= Price.MinLow(2, 1) Then
State = 3
End If
Else
State = 1
End If
If State = 4 Then Pass
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 3/20/2005 Posts: 45
|
Bruce,
Works great, as usual. Thanks
Dave
|
|
Guest-1 |