PureBytes Links
Trading Reference Links
|
> From omega-list-request@xxxxxxxxxx Tue Jan 13 22:28:05 1998
> Resent-Date: Tue, 13 Jan 1998 22:23:57 -0800
> X-Sender: robertwc@xxxxxxxxxx
> X-Mailer: QUALCOMM Windows Eudora Pro Version 4.0 Demo
> Date: Wed, 14 Jan 1998 00:23:36 -0600
> To: Omega-list@xxxxxxxxxx
> From: Robert W Cummings <robertwc@xxxxxxxxxx>
> Subject: El Help
> Mime-Version: 1.0
> Content-Type> : > text/plain> ; > charset="us-ascii">
> Resent-Message-Id: <"G74Nz2.0.36.yd5lq"@mx1>
> Resent-From: omega-list@xxxxxxxxxx
> X-Mailing-List: <omega-list@xxxxxxxxxx> archive/latest/13054
> X-Loop: omega-list@xxxxxxxxxx
> How would you write a statement that has opposite criteria requirements
> for the same plot.
> Example Inputs: CCILEV1(100), CCILEV1(-130)
>
> If O > O [1]and L > L [1] and CCI(10) [1] > CCILEV1 or < CCILEV2 then begin
> Plot1 (Low,"Low")
> end;
>
> Power Editor wont allow this, what do I need to do to have this plot both
> conditions when true.
> Thanks
> Robert
Good for you the Power Editor will not allow it. Otherwise it would probably
plot something different than you expect.
There are two problems. The first is the use of the "or <" construct. "or"
and "<" are called operators and expect to have an expression on the right
and left hand side of them. (A variable is an example of an expression, so
is a formula). You cannot have two operators side-by-side. (There are
exceptions, such as the negation sign).
The "or" operator is a boolean operator. It expects the expression on the
right and left of it to be true/false type equations. The "<" operator is
a relational operator and it expects numeric expression to the right and
left. (There are excpetions to this too but the essence of what I am saying
is true).
For example, you have "O>O[1]". This compares two numbers using the relational
operator. The relational operator produces a boolean result of either True or
False. Next you say "O>O[1] and L>L[1]". Here you have two relational
operator returning either True or False. This reduces the left and right hand
side of the "and" operator to boolean values. So after the relational expressions
are evaluated, the boolean "and" operation operates on the boolean true/false
result from the relational expressions.
Now we have a conundrum. How did easy language now I meant (O>O[1]) and (L>L[1])?
It could have been interpreted as O < (O[1] and L) > L[1]). This is clearly not
what I meant - I don't even know what that means. But if EL resolved boolean
operators with higher precedence than relational operator, this is what you would
have. It so happens that by default EL resolves relational expressions before
boolean expressions. Thus, EL will interpret your first couple of terms in the
way we would expect.
This gets to our second problem. Let's say I have decalare a bunch of boolean
variables, aa, bb, cc (lousy names!), etc. Now I say "If aa and bb or cc then ..."
I have a problem. Do I mean "(aa and bb) or cc" or do I mean "aa and (bb or cc)"?
It's just not clear. In my version of EL (TS 3.5), there is no defined precedence
for cascaded "and" and "or" operators. (Actually, there is but the manual says
there is not). Not only that, but it is unclear when you read it what you actually
mean.
So in these cases, you should use parentheses. Anything in parentheses is
evaluated first. (Think of it as the highest priority operator). You can even
have parentheses in parentheses. In this case the inner-most parentheses is
evaluated fist.
Now back to your question. I don't know how to answer it because I do not know
what you mean. (Neither did EL, hence the error message). I will take a guess
and show you one way of writing it correctly:
If (O > O[1])
and ( (CCI(10)[1] > CCILEV1) or (CCI(10)[1] < CCILEV2) ) then ...
In my writing of your equation I have two lines of tests. Both lines must pass
there test. (The equation is of the form "If line1 and line2"). The line 1 test
is easy to see - nice and readable. Even though I did not need parentheses I used
them - it eliminates all doubt as to what I mean.
Line 2 is a complex expression - it actually consists of 2 relational expresstions
plus a boolean expression. It is of the form "and (part1 or part2)". See how I
used parentheses to indicate I wnated the "or" performed before the "and". Again,
there is no doubt. Likewise the individual relational expressions of line 2 are
surrounded in parentheses - an overkill as operator precedence would have interpreted
it that way anyhow. But, nevertheless, it removes all doubt. In this case, sometimes
I would have used parentheses, other times I may not have - depending on what I
thought made it more readable and clear.
Hopefully, this has helped clarify things. Hopefully I did not throw too much
jargon in there either.
Chris Norrie
|