Switch and Timesincesignal

1.) I am trying to nest a SWITCH function in a what-if function:

V1 = CLOSE() > 10;
V2 = CLOSE() < -10;
V3 = SWITCH(V1,V2);
IF(V3=V1,1,0)

2.) I then applied a custom label:

Bullish Thrust == 1 green

Bearish Thrust == 0 red

 

3.) I also have another column that is using TimesSinceSignal

V1 = CLOSE() CrossesAbove 60;
V2 = CLOSE() CrossesBelow 40;
V3 = TIMESINCESIGNAL(V1, FIRSTSIGNALONLY=False);
V4 = TIMESINCESIGNAL(V2, FIRSTSIGNALONLY=False);
IF((V3<V4),V3,V4)

Can I do this? I am not getting the correct results?

thanks, Jamie

Hi Jamie,

When looking for equality between variables you need to use ‘==’ in the formula, so use this in the IF statement:

IF(V3==V1,1,0)

Regarding the TIMESINCESIGNAL, if you are trying to count how long it has been since it’s been above 60 you will need to look at it from the point of view of when it was last above 60 (not when it crossed above). Likewise, since it’s been below 40:

V1 = CLOSE() > 60;
V2 = CLOSE() < 40;
V3 = TIMESINCESIGNAL(V1);
V4 = TIMESINCESIGNAL(V2);
IF((V3<V4),V3,V4)

Finally, when posting formulas please use the <>Code button in the format bar which removes all formatting when copying and pasting in to Optuma. See this pinned post for instructions:

How to Add Code to Forum Posts