Bars Ago Node

The Bars Ago node gives you a series' value a set number of bars back, so a rule can compare now with then. How it counts, what it can read, and when Crossover or Price History is the better tool.

NodeBy AlgoLiftUpdated 4 min read
On this page 6How it worksExample: only buy while the 50 EMA is risingSettingsUse something else whenWhen it doesn't behaveGoing further

"Is it higher than it was?" might be the oldest question in technical trading. The Bars Ago node is how you ask it. Feed it a series, say how far back to look, and it hands you that series' value from that many bars ago. Put it beside the current value in a Comparison and you've got "the 50 EMA is rising" or "RSI is lower than it was five bars back".

Takes
One series: an indicator, a price, a level, price action, a memory or another modifier
Gives
That series' value N bars back
Reach for it
A rule compares a value now with the same value earlier

How it works

The count starts from the bar your rules are reading, which is the last completed bar. Indicators are read on that bar too, so an RSI and a Bars Ago 1 of that RSI are neighbors: the RSI of the latest completed bar, and the RSI of the bar before it. At 0 you get the last completed bar itself.

The bars it counts are its input's own bars. A Bars Ago 1 on an RSI built from a 1-hour series is an hour back, even in a strategy that trades 5-minute bars. And at the very start of the data, before there's anything that far back, the output is empty and a comparison against it reads false.

Like every modifier, it shifts a whole series, which the engine builds before the first bar runs. So its input has to be a series: an indicator, Current Price, a price-action output, an external data source, a level (Price History, Pivot Levels, Event Day or Bands), a Distance in standard deviations, a Since or Capture, a Crossover on the Bar close clock, or another modifier. A Math node, a Constant, a condition or a State Machine won't connect. One caution: Swing Points, Market Structure, Order Block, Fair Value Gap and Multi-Bar Formation keep their own memory through history, and the engine runs a backtest in monthly pieces, so a modifier over one of them reads an empty value for the first bars of each month. The builder warns when you wire one.

Current Price deserves its own warning. On a Comparison it's the live trade price, but a modifier can't hold a live price, so what reaches Bars Ago is the close of each completed bar. Bars Ago 1 of Current Price is the close of the bar before the latest completed one, which is one bar further back than most people expect.

Example: only buy while the 50 EMA is rising

You trade pullbacks on ES 15m and want them only while the trend is climbing. "Price above the 50 EMA" doesn't quite say it, because price can sit above an average that's flat or rolling over. You want the average itself to be going up.

Add an EMA with Period 50 and wire it into a Bars Ago with Value 5. Into a Comparison set to Greater Than, wire the EMA into a and the Bars Ago into b. It's true whenever the 50 EMA is higher than it was five bars (75 minutes) earlier. AND it with your pullback signal through a Logic node into the Entry.

Why five bars and not one? The EMA node's own Slope output already gives the one-bar change, and it flips sign on every small wiggle. Five bars asks for a rise you'd actually see on the chart.

Settings

Value
Default 1
How many bars back, from 0 to 999. 0 is the last completed bar itself.

Use something else when

You want the moment one line crosses another
Two Bars Ago nodes, two Comparisons and an AND is how crosses used to be built. The Crossover node does it in one, marks every cross on the chart, and catches the crosses the hand-built version misses.
The previous bar's high, or the 20-bar high
A level made of bar prices belongs in Price History, which reads the field you name (high, low, open, close) over completed bars. Bars Ago of Current Price only ever sees closes.
How much it changed, as a number
Rate of Change gives now minus then, or the percentage, in one node, ready for a threshold.
Something happened in the last N bars
"RSI was under 30 at some point in the last 10 bars" is one Since and one Comparison, not ten Bars Ago nodes.

When it doesn't behave

My hand-built crossover misses some crosses

"Below one bar ago, above now" skips the cross where the fast line touched the slow one, sat on it for a bar, then broke through. On the breaking bar the line was equal one bar ago, not below, so the rule never fires. The Crossover node handles the touch. Use it.

My “previous close” is a bar older than I meant

That's Current Price through a Bars Ago. It reads completed closes counted from the last completed bar, so Value 1 lands on the bar before the previous one. For the close of the latest completed bar, use a Price History reading the close over a one-bar window.

It won't take a Math node as its input

A Math node's result is worked out as the strategy runs, and a modifier needs the whole series up front. Shift the inputs instead: Bars Ago 5 of A, minus Bars Ago 5 of B, is the same number as A minus B five bars ago.

Going further

Modifiers chain, and Bars Ago is the one that makes chains interesting. Take a Rolling Min/Max Modifier giving the highest RSI of the last 10 bars, and a Bars Ago 10 of that same node: now you're comparing this stretch's peak momentum with the previous stretch's. A lower peak while price makes a higher high is the classic fading rally, and its momentum half is those three nodes and a Comparison.

The Value can be swept. Keep the steps coarse (3, 5, 10, 20) and remember what you're tuning: how far back "then" is. Fine-grained sweeps here find whichever lag happened to fit your sample, and every value you try counts against the project's search budget.

Or ask the copilot