Advanced Scripting


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".

As the name suggests, a modifier modifies the chosen indicator value. You can choose to leave the value unmodified ("Take the value as is"), or, modify it using these operations:

  • Look Back: refer to a previous value (that of the specified number of candles back in time).
  • Maximum/Minimum: given a configurable length `N`, it will return the maximum/minimum value encounter within the last `N` candles.
  • Simple Moving Average: take the simple moving average of the value over the last `N` candles.

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 use `a/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).
4 hours
Bollinger: Bands Width
a/b < 0.3
Simple Moving Average
Length 10
4 hours
of: Bollinger: Bands Width