ArchitectureStrategiesResearchWhy UsPricing
Time Series Lag Operator Custom & Factor Metrics

shift: Lag / Shift Operator

Shifts a time series by N periods to reference prior historical data point-in-time.

Visual Rule Syntax: close > @SMA(close, 50) and @shift(close, 1) <= @shift(@SMA(close, 50), 1)

Key Takeaways

  • Essential building block for detecting crossover and breakout moments.
  • Enforces strict Point-in-Time execution without accidental future data leakage.
  • Preserves time-series alignment across visual strategy rules.

What It Means in Simple Terms

The shift operator looks backwards in time. For example, `@shift(close, 1)` means 'give me yesterday's closing price.' `@shift(close, 5)` means 'give me the price from 5 trading days ago.' It lets you compare what is happening right now to what happened previously.

How It Helps You as an Investor

It allows you to detect precise crossover moments! To know if a moving average crossover happened today, you check: 'Is close > SMA today, AND was close <= SMA yesterday?' Without shift, you cannot build verified crossover logic.

Visual Node Rule Syntax & How to Plug in Values

Visual Node Expression No Code Required
close > @SMA(close, 50) and @shift(close, 1) <= @shift(@SMA(close, 50), 1)

Parameter Tuning & Market Calibration

The parameter $N$ is the number of bars to step back. For yesterday's value, use 1. For last week's value (daily bars), use 5. Always use $N \ge 1$ when looking backwards to avoid lookahead bias.

Input Fields & Parameters

Field / Parameter Type Default Role & Description
field field Required Historical input price or volume series from market feed.
timeperiod int Default Lookback period or tuning parameter for market calibration.

Mathematical Formulation

The mathematical definition of shift (Lag / Shift Operator) as evaluated within the Saral Engine execution pipeline:

Yt=Xt−nY_t = X_{t-n}

Variable & Parameter Definitions

Evaluates the value of series $X$ as of $n$ bars prior to the current bar $t$.

Systematic Strategy Applications

Confirmed Moving Average Cross Crossover Trigger
close > @SMA(close, 50) and @shift(close, 1) <= @shift(@SMA(close, 50), 1)

Triggers an entry strictly on the bar where close crosses above the 50-day average.

Common Questions & Practical Considerations

Does shift cause any execution delay?

No. When evaluating trading signals at the close of today's bar, using `@shift(close, 1)` accurately looks at yesterday's close. Your order executes cleanly at the next morning's market open (9:15 AM IST).