Forcing Binary Variable to Remain True

Good evening,

I am trying to create a binary +1, 0, -1 indicator and the variables triggering the binary value require two conditions to be true. One of the conditions is TurnsUp or TurnsDown and I am having trouble keeping the condition true until the next trigger takes place.

I have not included an effective neutral zone since that depends on the +1 or -1 conditions to have been met.

Using the conceptual script below:

IP = GETDATA(CODE=INDPRO:FRED);
6Chg = ROC(IP, BARS=6);
SmoothedChg = MA(6Chg, BARS=2, STYLE=Exponential);
12MASmoothedChg = MA(6Chg, BARS=12);
SD = STD(12MASmoothedChg, BARS=3);

Bearish = 12MASmoothedChg + (SD * 0.5);
Bullish = 12MASmoothedChg + (SD * -1.0);
BullMode = SmoothedChg < Bullish AND SmoothedChg TurnsUp;
BearMode = SmoothedChg > Bearish AND SmoothedChg TurnsDown;

IF(BullMode, 1, If(BearMode, -1, 0 ));

I am having trouble keeping the BullMode (+1) and BearMode (-1) until the next signal is triggered since TurnsUp / Down resets.

Additionally, there is a neutral zone ( 0 ), which is tricky as requires either the Bull or Bear mode to have been met, but then it fails.

The indicator turns 0 when SmoothedChg reverses back above Bearish
from a previously Bearish signal or back below Bullish from a bullish signal.

Here is what I have so far where the bottom panel is incorrect.

Thanks as always,

Eric

Hi Eric,

This is where you can use the SWITCH() function to turn the signal on when the 1st signal is true until the 2nd signal occurs.

Replace your last line from the IF statement to this, and see if that works:

SWITCH(BullMode, Bearmode)

Thank you - that got a me a little closer. My confusion was from something a bit more complicated.

How do you handle where one condition must happen before another condition in sequential order? In the example above, BullMode is currently:

BullMode = SmoothedChg < Bullish AND SmoothedChg TurnsUp;

But this is not always the case. The condition really needs to be something like:

SmoothedChg had previously been < Bulllish and then SmoothedChg TurnsUp.

SmoothedChg could have been < Bullish and since moved above the Bullish line before it actually turned up.

Right now, the conditions have to happen contemporaneously, which is not always the case.

Hopefully that makes sense.

Thanks Eric. We do have a SIGNALAFTER() function, so maybe that can be used instead?

That is what I needed - thank you. However, how can I create a neutral zone (0) whilst using the Switch function because of the TurnsUp?

I tried something like:

V1 = switch( Buy, Sell );
V2 = switch( Sell, Buy );
If(V1, 1, If(V2, -1, IF(Neutral, 0, ) ) );

But I still get 1 or -1 due to the Switch function.

Thanks for the assistance,

Eric

Hi Eric,

A switch can only have two states (on or off) so you would have to use another solution to have a 3rd state, such as using a multiple IF statement. This example will return a value of 1 if condition 1 is true, -1 if condition 2 is true, or 0 if neither.

IF(condition1, 1, (IF condition2, -1,0))

However, I don’t know how that can be combined with a switch without spending some time trying to work it out.