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
< (Less Than)
True if value to the left of < is less than the value to its right.
Example
>= (Greater Than or Equal)
True if value to the left of >= is greater or equal to the value to its right.
Example
<= (Less Than or Equal)
True if value to the left of <= is greater or equal to the value to its right.
Example
== (Equal)
True if value to the left of == is equal to the value to its right.
Example
!= (Not Equal)
True if value to the left of != is not equal to the value to its right.
Example
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
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
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 BA cross B = (A - B) * (A[1] - B[1]) < 0
Example
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 eitherTrue or False.
and
The
and operator return true if both expressions to its side are True.
Example
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
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 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.
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
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
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}, {b}, {c} are the step conditions.
Example
- 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)
! (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}, {b}, {c} are the step conditions and {d} is the invalidation condition.
Example
!.
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.
