Switch Function Issue

I tried creating a binary switch using variables from Swing Percentages, but am getting 0 values in the Show View.

BullPct = PERCENTSWING(PERCENT = -5.0);
BearPct = PERCENTSWING(PERCENT = 7.0);
Bear = SwingUp(BearPct);
Bull = SWINGDOWN(BullPct);
SWITCH(Bull < -0.050, Bear > 0.070);

However, if I do something like:

If ( Bull < -0.05, 1, Bear > 0.07, -1, 0 )) 

If works fine. The only issue is that I need to use switch so that the values are either 1 or 0.

What could I be missing?

Thanks,

EK

The PercentSwing can only be a positive number, so the BullPct should be 5, with the direction determined by the SwingDown. However, I would use TurnsDown and TurnsUp to get the signal days (so they occur once the required % moves have been made, ie not at the high and the low).

The Switch itself is true when the first condition is met (5% move from a high), and stays true until a 7% move off a low.

Does this do what you need?

BullPct = PERCENTSWING(PERCENT = 5.0);
BearPct = PERCENTSWING(PERCENT = 7.0);
Bear = BearPct TurnsUp;
Bull = BullPct TurnsDown ;
SWITCH(Bull, Bear);

Thank you for the assistance as always.

When I do the above and compare the ShowView below with the following code in the BackTester against SPX ( 2005 - 2022 ), I am holding cash at different times than the ShowView would indicate. Specifically in 2019.

Buy Signal

BullPct = PERCENTSWING(PERCENT = 5);
BearPct = PERCENTSWING(PERCENT = 11);

Bull = BullPct TurnsDown;
Bear = BearPct TurnsUp;

Bull

Sell Signal

BullPct = PERCENTSWING(PERCENT = 5);
BearPct = PERCENTSWING(PERCENT = 11);

Bull = BullPct TurnsDown;
Bear = BearPct TurnsUp;

Bear

This leads me to believe I am not representing the script from the ShowView correctly within BackTester.

Also, is there a way to display the PercentSwings in the top panel to verify the values? I only see one value option in Percent Swing Chart Overlay, but the high and low percentages are different in this case.

Thanks

Eric

Hi Eric,

Scripting and testing with swings can be quite complex because of the underlying data exposed in the testing engine (for a detailed explanation see here).

However, I think the issue may be that you are using different swing lengths, so the 11% swing won’t turn down after every 5% move as the 11% swing may not have turned up yet…

To display both swing values on the chart you would need to apply the overlay tool twice, one using 5% and the other 11%.