Change
[[change]] measures the absolute change in a price or series by computing the difference between its current value and the value observed a fixed number of candles earlier.
Block declaration
A strategy can contain multiple [[change]] blocks. Each block outputs a single numeric series corresponding to the difference with a fixed lag.
Examples
Minimal setup
This block measures the change from one close to the next.
[[change]]
id = "change"
length = 1Custom source and finding the optimal length
This block explores a range of values for length on the close series to identify the best-performing length.
[[change]]
id = "change"
source = "close"
length.start = 1
length.stop = 10
length.step = 1Variation of another indicator
This example applies change to an exponential moving average that has already been computed. It lets you measure the variation of a smoothed signal instead of working directly on raw prices.
[[moving_average]]
id = "ema_fast"
type = "ema"
length = 20
[[change]]
id = "ema_slope"
source = "ema_fast"
length = 1Parameters
| Parameter | Description |
|---|---|
idString Required | Unique identifier for the resulting series. |
sourceString or Array Optional | Input series used for the calculation. Accepted forms: source = "hl2" or source = ["close", "hl2"].Each value can be either a standard price source ( open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume) or the id of another indicator.Default value: "close" |
lengthInteger Required | Lag in bars; must be ≥ 1. Usage: • Fixed: length = value• Grid search: – length.start = min_value– length.stop = max_value– length.step = value (optional, default 1) |
symbolString or Array Optional | Market symbol(s) used when source only consists of standard prices (open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume).If source mixes standard prices and indicator ids, symbol is applied only to combinations based on standard prices.If source contains only indicator ids, symbol is ignored.If symbol is omitted, the block inherits the symbol defined in [backtest].For symbol format, arrays, and alignment rules, see Exchanges, Symbols and Timeframes. |
timeframeString or Array Optional | Timeframe on which this indicator is computed. If timeframe is omitted, the computation uses the grid’s main timeframe defined in [backtest].For accepted formats and timeframe alignment rules, see Exchanges, Symbols and Timeframes. |
Available variables
Use the block id directly in your expressions.
Assuming id = "change":
| Variable | Description |
|---|---|
change or change[0]Decimal | Current difference (e.g., close - close[1]). First length samples are NaN. |
change[n]Decimal | Value n bars ago (change[1] is the previous bar). |
change.lengthDecimal | Effective lag used during the current combination. |
change.sourceString | Actual source (close, high, another indicator). |
change.symbolString | Symbol used by this block. |
change.timeframeString | Timeframe used for the computation. |