How to code - if not true
Author: mikesblack
Creation Date: 8/18/2009 10:56 AM
profile picture

mikesblack

#1
From strategies from rules, I create a system that specifies that if some condition or group of conditions are true then- execute some order.

After opening into the strategy window, how can I take that and then convert that into, -if some condition or group of conditions are false- then execute?
-
Microsoft C# Programming for the Absolute Beginner- Hmm.. Just purchased it from Amazon. Might end up being a good investment. Thanks for the suggestion.
profile picture

Eugene

#2
In pseudocode:

CODE:
Please log in to see this code.


"if( !condition )" can be rephrased as "if( condition == false )".
profile picture

mikesblack

#3
Thanks Eugene.
profile picture

StratCat

#4
I realize this is an old post but the question probably comes up often... Sometimes the easiest way to write logic for binary operators is to negate the easiest condition. For example:

Eugene's original condition is (un-negated):
if( Close[bar] > Close[bar-1] ) {...}
is the same as -
if( Close[bar-1] < Close[bar] ) { ... }

... the opposite is...
if( !(Close[bar-1] < Close[bar]) ) {...}
or
if( Close[bar-1] < Close[bar] == false ) {...}

... also, you can express this by testing for the actual condition you want...
if( Close[bar-1] >= Close[bar] ) {...}


An example of when you'd actually write logic like this is mostly when dealing with two (or more) variables. For example, to do something between 9:30 and 3:30 you could test for what you don't want and then negate it to get what you do want:

if( !((nHour == 9 && nMinute < 30) || (nHour == 15 && nMinute > 30)) ) {...}

... of couse you'd need another condition to handle 16 (e.g. 4:pm) if this were a regular hours trading thing but you get the point. Doing it any other way is more confusing w/o using time conversions.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).