I'm trying to use nested IIF functions to determine whether I want to be
long, short or flat a given asset. The way I specify the code, it seems
as though the variable I'm using (which I call "Stance") should only
take values -1, 0, or 1. However, when I plot "Stance," it takes on
continuous values between 0 and 1, which is baffling to me. I was hoping
someone could take a look at the line below to see if something jumps
out as obviously wrong:

Stance[0] = 0;
Stance = IIF( Ref(Stance, -1) == 0, IIF( A1 > A2  AND  B1 < B2  AND  C1
> C2, 1, IIF( A1 < A2  AND  B1 > B2  AND  C1 < C2, -1, 0), IIF(
Ref(Stance, -1) == 1, IIF(A1 < A2  AND  B1 > B2  AND  C1 < C2, -1, IIF(
A1 < A2  OR  B1 > B3, 0, Ref(Stance, -1))), IIF( A1 > A2  AND  B1 < B2 
AND  C1 > C2, 1, IIF( A1 > A2  OR  B1 < B4, 0, Ref(Stance, -1)))));

In words: if yesterday's stance is zero, then check to see if the
strategy wants to go long, go short, or remain flat. If yesterday's
stance is long (i.e., 1), then check to see if it wants to go short or
get flat (if neither, then stay long). Else if yesterday's stance is
short (i.e., -1), then check to see if it wants to go long or get flat
(if neither, then stay short).

The conditions  are all mutually exclusive, so I'm having a hard time
understanding why anything other than -1, 0, or 1 should be returned by
the variable Stance. I would be grateful for any insight that anyone may
have.

Regards,
Ray Micaletti



Reply via email to