Systemicbeta

Lag

systemic:core-lagMath

Inputs

NameTypeDescription
PeriodsWhole numberHow many earlier values to look back: a whole number, 0 or more.
SeriesNumber seriesThe series of values you want to look back through: prices, returns, indicator values, or another module's output.

Outputs

NameTypeDescription
ShiftedNumber seriesThe earlier value selected by **Periods**, in the same unit and on the same bars as **Series**.

Cost

6
credits per run
1,000
bars

0.205 + 0.00563·n credits for n bars, rounded up. The marks are each plan's limit of bars.

A price rises today, but compared with which earlier price? Yesterday's? The last value before a data gap? Lag puts an earlier value of a series next to the current one, so you can compare them in the rest of your strategy.

Choose Periods, a whole number (0 or more) of earlier bars that have a value. Lag counts the values in the connected series, not clock time, and never uses a value from the future. With Periods = 0, it keeps the current value. In a complete series, this is the familiar lag by observations. Gaps change what counts as the previous value.

Lag⁡k(X)t=xj−k,j=number of bars with a value up to bar t.\operatorname{Lag}_{k}(X)_t=x_{j-k}, \qquad j=\text{number of bars with a value up to bar }t.

Here (k) is Periods and (x_j) is the (j)th value in the series. The formula applies when the current bar has a value and at least (k) earlier values exist. Otherwise the output is empty (null).

Walk through a gap

Set Periods = 1 for the small series below. These are example numbers, not market prices.

BarSeriesShiftedWhat happened
110emptyNo earlier value.
2emptyemptyNo value on this bar.
3emptyemptyNo value on this bar.
4010Zero is the next value; the value before it is 10.
5200The value before it is zero.
6emptyemptyNo value on this bar.
7emptyemptyNo value on this bar.
83020The value before it is 20.

An empty bar does not count toward the lookback, and its own output is empty. Zero counts. That is why bar 5 receives zero, not 10.

With Periods = 2, bar 5 would receive 10: the second earlier value. With Periods = 0, each value stays on its own bar; empty bars stay empty. A larger setting leaves more bars empty at the start, until enough values exist.

If you think in days or hours, check the period of the input first. On a complete daily series, five values may cover five trading sessions. Across a missing bar they span longer. If a slower series was aligned to a faster timeline by repeating its latest value, each repeated value counts as a value here.

Questions you can build

How much did the latest reading change?

Connect a price or indicator to Lag → Series with Periods = 1. Put the original series in Subtract → First Value and Shifted in Subtract → Second Value. The result is an absolute change in the same unit: dollars for a dollar price, percentage points for a percentage. For a relative change, divide that difference by Shifted, but only where Shifted is not zero. An empty result tells you that one of the two values is missing.

Try this: Plot an indicator next to its value shifted by one. When they move apart, look at the original data. Did the indicator really move, or did a gap make the comparison span more time than expected?

Does a weekly comparison mean a calendar week?

On a daily series, Periods = 5 compares with the fifth earlier value. This is close to a trading-week comparison when the series is complete, but the setting does not promise five calendar days. Holidays, missing bars and earlier alignment all change the time between the two values.

Try this: Compare a Lag of five on a complete daily series and on one with missing bars. Check the dates behind the shifted values before you interpret the change.

Did one series move first?

Shift a return series with Lag and compare it with a second return series using Correlation Coefficient: connect Shifted to its First Dataset and the second return series to Second Dataset. Then compare Periods = 0, 1, 2 with the same correlation window and repeat the test on a different date range. This is a lagged-correlation question. It is not evidence of causation, and it does not prove that a signal arrives early enough to trade.

Try this: Look at shifts of one and two separately. If a relationship appears at only one setting or in only one date range, what does that say about its stability?

Reading Shifted

Lag keeps the unit of Series and has one value per bar of the input. The output is empty on a bar where the current value is missing or where there are not enough earlier values. Lag can only look back inside the history of the run; a value before the start of that history is not available.

© 2026 WanoLabs. All rights reservedBeta v0.1.5