Momentum (mom)
[[mom]] measures the raw change in its source between the current candle and its value length candles ago. It produces one unbounded series expressed in the same unit as the source.
A positive value means the source is above its past value, a negative value means it is below it, and zero means the two values are equal. Distance from zero represents the size of the change. Because the result is not normalized, its magnitude also depends on the scale of the source: momentum is a raw difference in source units, not a percentage.
Block declaration
A strategy can contain multiple [[mom]] blocks. Each block outputs one numeric series: the gap between the source and its value length candles earlier.
Examples
Minimal setup
This block measures the momentum of the close series over 10 candles. Since source is omitted, it defaults to close. It uses the main symbol and timeframe defined in [backtest].
[[mom]]
id = "mom"
length = 10Specific source
This block computes momentum on the hlc3 source (average of high, low, and close) instead of close.
[[mom]]
id = "mom"
source = "hlc3"
length = 10Source from another indicator
This block measures the momentum of the series produced by the rsi block, that is, how far the RSI has moved over 5 candles.
[[rsi]]
id = "rsi"
length = 14
[[mom]]
id = "rsi_mom"
source = "rsi"
length = 5Search for the optimal length
This block explores a range of length values to identify the best-performing distance.
[[mom]]
id = "mom"
length.start = 5
length.stop = 30
length.step = 5Dedicated symbol and timeframe
In this configuration, momentum runs on the daily series from BINANCE:ETHUSDT, independently of the primary symbol and timeframe used by the rest of the strategy. See Exchanges, Symbols and Timeframes for alignment rules.
[[mom]]
id = "mom"
length = 10
symbol = "BINANCE:ETHUSDT"
timeframe = "D"Parameters
| Parameter | Description |
|---|---|
idString Required | Unique name identifying the mom series; the block exposes one numeric series with this identifier. |
sourceString or Array Optional | Input series used for the calculation. Accepted forms: source = "hlc3" or source = ["close", "hlc3"].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 | Number of candles separating the current value from the past value it is compared with; must be between 1 and 10000.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) that provide the source series when source contains 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.For format and alignment details, 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
The mom block exposes one numeric series, its calculation length, and metadata about the input source, symbol, and timeframe. You can use these identifiers directly inside your expressions.
Assume the block is configured as:
[[mom]]
id = "mom"
source = "close"
length = 10Then:
| Variable | Description |
|---|---|
mom or mom[0]Decimal | Current momentum value (gap between the source and its value length candles ago). |
mom[n]Decimal | Momentum value from n candles ago. |
mom.lengthDecimal | Distance in candles used for the calculation. |
mom.sourceString | Name of the input source series (e.g., close, hlc3, or another indicator id). |
mom.symbolString | Symbol from which the input data is read. |
mom.timeframeString | Timeframe on which the mom is computed. |
Notes
- During warm-up, the first
lengthcandles have no past value available and the series isNaN. If any value inside the window isNaN, the result for that candle isNaNas well. - Numeric variables support arithmetic, comparisons, and logical operators.
- Text variables are strings intended for equality/inequality checks only.