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

Coding needed for new condition Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
jrixey
Posted : Thursday, October 20, 2011 11:44:47 AM
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!
Bruce_L
Posted : Thursday, October 20, 2011 11:48:30 AM


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
jrixey
Posted : Thursday, October 20, 2011 12:02:58 PM
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?
Bruce_L
Posted : Thursday, October 20, 2011 12:07:40 PM


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
jrixey
Posted : Thursday, October 20, 2011 12:15:26 PM
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!
Bruce_L
Posted : Thursday, October 20, 2011 12:20:49 PM


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
jrixey
Posted : Thursday, October 20, 2011 12:54:24 PM
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!
Bruce_L
Posted : Thursday, October 20, 2011 1:04:23 PM


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
jrixey
Posted : Thursday, October 20, 2011 1:19:25 PM
Registered User
Joined: 10/7/2004
Posts: 45
That is a thing of beauty, Bruce! Thanks VERY much!!
Bruce_L
Posted : Thursday, October 20, 2011 1:24:34 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You're welcome.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jas0501
Posted : Saturday, October 22, 2011 12:35:13 PM
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.

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.