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.

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:

Synthax
{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.