Switch() Function

Author: Optuma Team Last updated: Jun 20, 2020 12:35

Overview

The SWITCH() function uses two Boolean (true/false) conditions, with the first signal being true until the second condition is met. It will then remain off until the first condition is met again.

The primary use of this function would be any situation where you may wish to set an upper-value target and a different lower-value target as true/false signals.

In this example, a Show View tool has been applied using the following script formula to display the green shaded zones:

H1 = HIGH() > HIGHESTHIGH(BARS=66);  
L1 = LOW() < LOWESTLOW(BARS=66);
SWITCH(H1,L1)

Show View Tool

H1 is true when there’s a higher 66 day high
L1 is true when there’s a lower 66 day low

The formula shows true (ie switches on) when there’s a new 66 day high after a lower 66 day low. It switches off when a lower 66 day low is made, and so on.

In another example, the chart of gold is displayed with a Show View tool applied based on RSI. The script has been set to:

SWITCH(RSI() > 70, RSI() < 30)

The green areas of the Show View tool begin where the RSI is greater than 70, and remains until the value is less than 30. It doesn’t switch on again until the RSI crosses 70:

Show View Tool

Note that it’s possible to click and drag the Show View over the price chart or indicator panel:

Show View Tool