Logical

Description

The following logical operators are available in thinkScript®:

Operator Description
is true logical value
!, is false logical NOT
and, && logical AND
or logical OR

Logical operators can be applied only to numeric data. Zero(0) is interpreted as a false value; all other values are interpreted as a true value. Therefore, expression x is true returns true when x is non-zero, and false when x is zero.

Consider the following rules when using the logical operators:

Logical NOT is true when the argument is false. For some expression x, it can be written as !x or x is false.

Logical AND is true when both arguments are true. Logical OR is true when at least one argument is true.

For examples of usage of is true and is false operators, refer to the is reserved word article.

Example 1

plot LocalMinimum = low < low[1] and low < low[-1];
LocalMinimum.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

Highlights local minumums of the lowest price.

Example 2

plot signal = open == high or close == high;
signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Highlights moments, when the open or close price is the highest.

Example 3

input bubble = yes;
AddChartBubble(bubble and barNumber() == 1, high, "Displaying a bubble");
AddLabel(!bubble, "Displaying a label");

Draws a cloud or label near the first bar depending on the parameter. The label is displayed when the the bubble parameter is set to no.