Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 10/7/2004 Posts: 45
|
Good morning! I hope you folks can help me code a new condition which would be true for either an up bar when the last is in the upper half of the bars range or a down bar where the last in in the lower half of the bars range.Thanks very much!
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
A RealCode Condition for Price being above the midpoint of the Bar would be:
If Price.Last > (Price.High + Price.Low) / 2 Then Pass
A RealCode Condition for Price being below the midpoint of the Bar would be:
If Price.Last < (Price.High + Price.Low) / 2 Then Pass
Writing Conditions in RealCode
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/7/2004 Posts: 45
|
Thanks very much! How would I combine those into a single condition which would look for either part to be true?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Maybe I am misunderstanding your request, but with the exception of when the Close is exactly at the midpoint of the bar, one or the other is always true. This means the Condition would almost always be true.
If you in fact meant "up bar" not to be defined by being in the upper half of the bars range, but to be an additional requirement, what do you mean by "up bar"? That there is a positive net change from the previous bar? That the close is above the open? Something else entirely?
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/7/2004 Posts: 45
|
Sorry I Didn't make this clear! "Upbar" or "Downbar" would be an additional requirement, meanig the the close (most recent price) is above or below, respectively the bar's open. Sorry again for the confusion!
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
A RealCode Condition for your up bar would be:
If Price.Last > Price.Open AndAlso _
Price.Last > (Price.High + Price.Low) / 2 Then Pass
A RealCode Condition for your down bar would be:
If Price.Last < Price.Open AndAlso _
Price.Last < (Price.High + Price.Low) / 2 Then Pass
A RealCode Condition for either being true would be:
If (Price.Last > Price.Open AndAlso _
Price.Last > (Price.High + Price.Low) / 2) OrElse _
(Price.Last < Price.Open AndAlso _
Price.Last < (Price.High + Price.Low) / 2) Then Pass
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/7/2004 Posts: 45
|
Bruce - Got it in the program but it's still not quite what i'm looking for. What if we add the requirement that the open and close are in the upper half of an up bar or the lower half of a down bar? Also, for an up bar, the last must be above the open, and for a down bar the last must be below the open. In other words, I'm looking for "hammers" and "shooting stars" in candlestick terms.Thanks for putting up with me!
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
A RealCode Condition for your up bar would be:
If Price.Last > Price.Open AndAlso _
Price.Open > (Price.High + Price.Low) / 2 Then Pass
A RealCode Condition for your down bar would be:
If Price.Last < Price.Open AndAlso _
Price.Open < (Price.High + Price.Low) / 2 Then Pass
A RealCode Condition for either being true would be:
If (Price.Last > Price.Open AndAlso _
Price.Open > (Price.High + Price.Low) / 2) OrElse _
(Price.Last < Price.Open AndAlso _
Price.Open < (Price.High + Price.Low) / 2) Then Pass
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/7/2004 Posts: 45
|
That is a thing of beauty, Bruce! Thanks VERY much!!
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
QUOTE (Bruce_L) A RealCode Condition for your up bar would be:
If Price.Last > Price.Open AndAlso _
Price.Open > (Price.High + Price.Low) / 2 Then Pass
A RealCode Condition for your down bar would be:
If Price.Last < Price.Open AndAlso _
Price.Open < (Price.High + Price.Low) / 2 Then Pass
A RealCode Condition for either being true would be:
If (Price.Last > Price.Open AndAlso _
Price.Open > (Price.High + Price.Low) / 2) OrElse _
(Price.Last < Price.Open AndAlso _
Price.Open < (Price.High + Price.Low) / 2) Then Pass
For those not versed in coding an explanation might be instructive, The code is a compound condition in the form
If A or B then pass
where both conditions are compound
A is in the form A1 and A2 and B in the form B1 and B2
Composting this into
If A1 and A2 or B1 and B2 then pass
would be logically incorrect. Adding parenthesis ensures the the condition is evaluated correctly
If (A1 and A2) or
(B1 and B2) then pass
Side note; The use of AndAlso is equivalent or And, but does cause shortcircuiting when any condition is not satisfied, creating more efficient code.
|
|
Guest-1 |