Skip to main content
Operators are specific tokens (characters) performing an operation over multiple defined elements. Alert scripting supports three types of operators described below.

Comparison Operators

Comparison operators are used to compare two numerical values with each other.

> (Greater Than)


True if value to the left of > is greater than the value to its right.
Example
{close} > {open}

< (Less Than)


True if value to the left of < is less than the value to its right.
Example
{close} < {open}

>= (Greater Than or Equal)


True if value to the left of >= is greater or equal to the value to its right.
Example
{close} >= {open}

<= (Less Than or Equal)


True if value to the left of <= is greater or equal to the value to its right.
Example
{close} <= {open}

== (Equal)


True if value to the left of == is equal to the value to its right.
Example
{close} == {open}

!= (Not Equal)


True if value to the left of != is not equal to the value to its right.
Example
{close} != {open}

crossover


True if series to the left of crossover is crossing over the series to its right. Also expressed as:
  • A crossover B = A > B and A[1] < B[1]
Example
{close} crossover {open}
crossover is not a traditional operator but serves a comparative purpose for alert scripting.

crossunder


True if the series to the left of crossunder is crossing under the series to its right. Also expressed as:
  • A crossunder B = A < B and A[1] > B[1]
Example
{close} crossunder {open}
crossunder is not a traditional operator but serves a comparative purpose for alert scripting.

cross


True if the series to the left of cross is crossing (either over or under) the series to its right. Also expressed as:
  • A cross B = A crossover B or A crossunder B
  • A cross B = (A - B) * (A[1] - B[1]) < 0
Example
{close} cross {open}
cross is not a traditional operator but serves a comparative purpose for alert scripting.

Logical Operators

Logical operators link two expressions together forming a more complex condition being either True or False.

and


The and operator return true if both expressions to its side are True.
Example
{close} > {open} and {volume} > 1000
The above return True if the closing price is greater than the opening price while the volume is greater than 1000.

or


The or operator return true if either one of the expressions to its side are True.
Example
{close} > {open} or {close} > {hl2}
The above return True if the closing price is greater than the opening price or if the closing price is greater than the median price hl2. It is important to note that or takes precedence over and, for example:
{close} > {open} and {volume} > 1000 or {close} > {hl2} and {volume} > 1000
In the above condition {close} > {open} and {volume} > 1000 and {close} > {hl2} and {volume} > 1000 would be evaluated first.

not

The not operator test if a following condition is true or false, returning True if the condition is False.
not {close} > {open}
The above return True if the closing price is not greater than the opening price.

History Referencing Operator []

Users can refer to previous values of a series using the historical referencing operator []. This operator is placed to the right of a placeholder within the curly brackets:
Syntax
{A[n]}
Where n is a numerical value determining the number of bars back to go fetching {A}. For example, if we want to get the previous value of the closing price we can use {close[1]}.
Example
{close} > {close[1]}
The above example return True if the current closing price is greater than value of the closing price one bar back.

Sequence Operators

Sequence related operators allow defining and controling sequences.
A sequence is a structure made of steps. When one step is triggered we switch to the next step on the next bar.If there are no more steps to evaluate we say that the sequence is complete and start from the first step again.

then


Operator defining a sequence. Each condition in between then is a step, with the first step being the leftmost condition before then.
Syntax
{a} then {b} then {c}
Where {a}, {b}, {c} are the step conditions.
Example
{close} > {open} then {close} < {open} then {close} > {open} and {volume} > 1000
In the above example we have a sequence with 3 steps:
  • Step 1: {close} > {open} (is the closing price greater than the open price)
  • Step 2: {close} < {open} (is the closing price lower than the open price)
  • Step 3: {close} > {open} and {volume} > 1000 (is the closing price greater than the open price and volume above 1000)
We first evaluate step 1, if it is true we will start evaluating step 2 starting at the next bar. Once step 2 is true, we will finally start evaluating step 3 sarting at the next bar. Step 3 is the last step of our sequence, once it is true the sequence will be complete and will restart evaluating from step 1 at the next bar.

! (Inline Invalidation)


Operator invalidating a sequence if the assocated condition is true. Inline invalidation always takes place before the evaluation of a sequence step.
Invalidation reffer to restarting a sequence prematurely before it is complete.
Syntax
{a} then {b} then {c} ! {d}
Where {a}, {b}, {c} are the step conditions and {d} is the invalidation condition.
Example
{close} > {open} then {close} > {open} then {close} > {open} ! {close} < {open}
In the above example we have a 3 step sequence using the same conditions (closing price greater than the opening price), and an inline invalidation condition defined after the invalidation operator !. Before evaluating any step from the sequence, the invalidation condition will be checked first, if it is true then we reset the sequence to step 1, after this we immediately evaluate the sequence from step 1.