Lag¶
Math · Temporal
Shift a series back by N bars — at bar i, emits the value from bar (i − N). Useful for 'price now vs price N bars ago' comparisons. First N bars emit NaN (no value to look back to).
Lag shifts a series back in time: at the current bar it reports the value from N bars ago. It's how you bring the past into the present so you can compare them — "is price higher than it was 10 bars ago?", "is this indicator above its own value from last week?" Lag gives you the historical value as a series you can feed into any comparison.
How it works¶
Each bar the block emits the source value from Lag (bars) ago (default 1) — a.shift(bars). The first N bars have nothing to look back to and emit NaN. Note the difference from Diff: Lag gives you the old value itself, while Diff gives you the difference between now and then. Lag plus a Subtract equals Diff.
When to use it¶
Use Lag whenever you need to compare the present to a specific point in the past. Wire price into a Greater Than with its own Lag to ask "higher than N bars ago?" — a crude but effective momentum/trend check. It's also how you align a value with its earlier self for custom rate-of-change or echo logic. Any "now versus then" comparison starts with a Lag.
Example¶
Simple momentum check: Lag price by 10 bars, then Greater Than with current price as A and the lagged series as B — true when price is higher than it was 10 bars ago. Use it as a trend condition in an And gate and backtest in the Tester.
Tips & gotchas¶
- It gives the old value — Diff gives the change; Lag + Subtract = Diff.
- First N bars are NaN — nothing to look back to.
- The basis of "now vs then" comparisons.
- Don't confuse with Delay — Lag shifts a value series back for comparison; Delay shifts a signal later in time.
Related blocks¶
Inputs¶
| Socket | Type | What to wire in |
|---|---|---|
| In | series / bars |
Source series. BARS input uses close. |
Outputs¶
| Output | Type | Plots as | Description |
|---|---|---|---|
| Lagged | series |
Line · sub-pane | Source series shifted back by bars. |
Parameters¶
| Parameter | Type | Default | What it does |
|---|---|---|---|
| Lag (bars) | number · 1–500 | 1 |
How many bars to look back. |
Reference auto-generated from the block catalog · category Math.