Advanced Scripting

Modifiers

In the previous section you have learned all about the basic structure of a script, combining and comparing multiple indicator values. For more advanced setups, a simple comparison is not sufficient. For example, there are cases where you need to compare the current value of an indicator to that of the previous candle, or to the moving average over a certain number of previous candles. Scripting is expressive enough to cover these cases as well, using a concept called "Modifiers". See modifiers for information on all available modifiers.

Custom Comparison Formulas

Using the regular comparison operators, you can easily check whether or not one value is greater than the other. But, at times you need more control over the comparison. For example, what if you want to make sure that the current value grew by 50% compared to the previous value? Scripting has this covered as well.

If you select the ƒ comparison operator you are able to input a custom comparison. Here, you can use identifiers a and b to refer to the expressions (A) respectively (B). Assuming expression (A) is configured to the current value, and (B) to the previous value, you can usea/b > 1.5 to check if the value grew by 50%.

Next to referring to identifiers a and b you can also refer to open, high, low, and close in order to obtain the current OHLC values.

Putting it all together

Now, let us put together what we have learned so far by setting up a script that triggers on a Bollinger Bands squeeze. The main ingredients are:

  • The current value of the Bollinger Bands Width, expression (A).
  • The moving average of the Bollinger Bands Width over the last 10 candles, expression (B).
  • A custom comparison, asserting that the current value is only 30% of the average (the squeeze).
FIRST EXPRESSION (A)
4 hours
Bollinger: Bands Width
Length20
K2
COMPARISON OPERATOR
<>=ƒ
a/b < 0.3
SECOND EXPRESSION (B)
Simple Moving Average
Length 10
4 hours
of: Bollinger: Bands Width
Length10
K2