OPEN-SOURCE SCRIPT
Güncellendi Index Lead Lag [BMT]

Index Lead Lag [BMT]
Which of NQ, ES, YM and RTY is leading, and specifically whether NQ is. All four are measured from one shared anchor so the differences between them are relative strength, not four unrelated returns; vertical order in the pane is the ranking and a crossover is a change of leadership. Beta-adjust vs ES answers the harder question: is NQ leading by more than its beta to ES already implies?
What it draws
One line per index: its percent change from the anchor bar, on the chart's own timeframe. The gap between NQ and ES is filled, cyan while NQ is ahead and neutral while it is not, so the pane lights up on the state you are watching for. A dashed zero line, a vertical line at the anchor bar, and faint bands on the bars that were earlier anchors, so a reset is visible as it happens.
The anchor
Measure picks the bar every index is measured from. All four always share it.
The period anchors are read as prices (the open of the current day, week, month or quarter, from a higher-timeframe request) rather than counted back as bars, so there is no history-buffer limit on how far back an anchor can sit.
Beta-adjust vs ES
NQ's beta to ES has run about 1.67, so NQ beats ES on nearly every up day whether or not it is leading, and zero is the wrong threshold on a plain difference. With Beta-adjust on, each index has beta times the ES move subtracted, leaving a residual: zero means it moved exactly as its beta implies, above zero is genuine leadership, below zero is a quiet failure even on a green day. ES sits flat on zero by construction, and the NQ-ES fill becomes the residual itself.
Beta is the ordinary least squares slope of each index against ES over a settable window (90 bars by default) of the chart's own timeframe, fitted on the bars before the one being scored so a bar cannot explain itself away. The window applies with Beta-adjust off as well, because the markers, ribbon and chart tint are built from the residual either way.
Divergence markers
A small triangle at the top of the pane on any bar where NQ sits beyond a threshold above (green, leading) or below (red, lagging) the path its beta implies. Hover one for its sigma and a one-line reading. The threshold is in standard deviations of where the residual could have drifted by now under chance, per-bar noise times the square root of bars since the anchor, so early in a period it takes less and late in a period it takes more, rather than one yardstick set by the period's average. The sigma value is also in the data window.
Ribbon
With the index lines off, the pane collapses to a strip of dots and the table: green while NQ beats its beta, red while it misses it, grey between, or coloured by the current leader instead, which is gated on the leader-to-laggard spread being wider than its recent average so it does not flicker while the four are bunched. The same message at a fraction of the weight, in a pane you can shrink to a strip.
The chart symbol
Whatever symbol the chart is on gets its own column, run through the same machinery but against NQ rather than ES, so it reads as "is this name adding something of its own beyond how much more it moves than the Nasdaq". Its lead is marked confirmed only when the name is also at a period high NQ has not made: beating a beta while quiet is a read that inverts by regime, and the upside leg is the half that holds. A conditional profile shows what the name has averaged while NQ was leading its own beta versus while NQ was lagging, so a wide gap says it rides megacap leadership and two similar numbers say the index regime tells you nothing about it. An optional tint paints the price chart green or red by the symbol's state. Turn the column off on an index chart, where it restates one you already have.
Status table
Columns sort strongest first, so the table reads left to right as a ranking and a change of column order is the signal. Each column shows the value and, under Beta-adjust, the beta it was measured against. Held counts bars since the leader last changed; Ref names the anchor in force. The leader-to-laggard spread is on the status line. Location and font size are inputs. RTY can be excluded, since its correlation to ES is lower and it reaches the extremes on idiosyncratic moves rather than leadership.
Colors
Red and green are avoided for the lines on purpose, since on a chart they already mean down and up and a red leader reads as a falling index. The four hues are held close in brightness so no index visually outweighs another, ES the neutral one because it is the benchmark, and the set flips with the chart background.
Notes
Each index is a handful of requests: its close on the chart timeframe; its session open, prior close and N-sessions-ago close in one daily request; and the week, month and quarter opens. The higher-timeframe requests use lookahead on, which is safe for an open or for the close of a session that has already ended. Everything else, beta included, is computed on the chart's own bars.
Which of NQ, ES, YM and RTY is leading, and specifically whether NQ is. All four are measured from one shared anchor so the differences between them are relative strength, not four unrelated returns; vertical order in the pane is the ranking and a crossover is a change of leadership. Beta-adjust vs ES answers the harder question: is NQ leading by more than its beta to ES already implies?
What it draws
One line per index: its percent change from the anchor bar, on the chart's own timeframe. The gap between NQ and ES is filled, cyan while NQ is ahead and neutral while it is not, so the pane lights up on the state you are watching for. A dashed zero line, a vertical line at the anchor bar, and faint bands on the bars that were earlier anchors, so a reset is visible as it happens.
The anchor
Measure picks the bar every index is measured from. All four always share it.
- Auto (default) chooses from the chart timeframe: session open under an hour, week open intraday above that, month open on a daily chart, quarter open above. The table's Ref cell shows what it resolved to.
- Session open, Prior close, Week open, Month open, Quarter open. Each resets on its boundary, so the pane reads as leadership within the period to date. The gap between Prior close and Session open is the overnight move.
- N sessions: the close N daily sessions ago. Rolling, and the same thing on every chart timeframe.
- ES swing low / ES swing high: the lowest low or highest high ES has printed in the range on screen, so it reads as "since the market turned, who led?". Pan or zoom and it re-resolves to the new view.
- Fixed date: by default the current session's open, rolling forward each day; turn that off to pin a date with the date picker.
The period anchors are read as prices (the open of the current day, week, month or quarter, from a higher-timeframe request) rather than counted back as bars, so there is no history-buffer limit on how far back an anchor can sit.
Beta-adjust vs ES
NQ's beta to ES has run about 1.67, so NQ beats ES on nearly every up day whether or not it is leading, and zero is the wrong threshold on a plain difference. With Beta-adjust on, each index has beta times the ES move subtracted, leaving a residual: zero means it moved exactly as its beta implies, above zero is genuine leadership, below zero is a quiet failure even on a green day. ES sits flat on zero by construction, and the NQ-ES fill becomes the residual itself.
Beta is the ordinary least squares slope of each index against ES over a settable window (90 bars by default) of the chart's own timeframe, fitted on the bars before the one being scored so a bar cannot explain itself away. The window applies with Beta-adjust off as well, because the markers, ribbon and chart tint are built from the residual either way.
Divergence markers
A small triangle at the top of the pane on any bar where NQ sits beyond a threshold above (green, leading) or below (red, lagging) the path its beta implies. Hover one for its sigma and a one-line reading. The threshold is in standard deviations of where the residual could have drifted by now under chance, per-bar noise times the square root of bars since the anchor, so early in a period it takes less and late in a period it takes more, rather than one yardstick set by the period's average. The sigma value is also in the data window.
Ribbon
With the index lines off, the pane collapses to a strip of dots and the table: green while NQ beats its beta, red while it misses it, grey between, or coloured by the current leader instead, which is gated on the leader-to-laggard spread being wider than its recent average so it does not flicker while the four are bunched. The same message at a fraction of the weight, in a pane you can shrink to a strip.
The chart symbol
Whatever symbol the chart is on gets its own column, run through the same machinery but against NQ rather than ES, so it reads as "is this name adding something of its own beyond how much more it moves than the Nasdaq". Its lead is marked confirmed only when the name is also at a period high NQ has not made: beating a beta while quiet is a read that inverts by regime, and the upside leg is the half that holds. A conditional profile shows what the name has averaged while NQ was leading its own beta versus while NQ was lagging, so a wide gap says it rides megacap leadership and two similar numbers say the index regime tells you nothing about it. An optional tint paints the price chart green or red by the symbol's state. Turn the column off on an index chart, where it restates one you already have.
Status table
Columns sort strongest first, so the table reads left to right as a ranking and a change of column order is the signal. Each column shows the value and, under Beta-adjust, the beta it was measured against. Held counts bars since the leader last changed; Ref names the anchor in force. The leader-to-laggard spread is on the status line. Location and font size are inputs. RTY can be excluded, since its correlation to ES is lower and it reaches the extremes on idiosyncratic moves rather than leadership.
Colors
Red and green are avoided for the lines on purpose, since on a chart they already mean down and up and a red leader reads as a falling index. The four hues are held close in brightness so no index visually outweighs another, ES the neutral one because it is the benchmark, and the set flips with the chart background.
Notes
Each index is a handful of requests: its close on the chart timeframe; its session open, prior close and N-sessions-ago close in one daily request; and the week, month and quarter opens. The higher-timeframe requests use lookahead on, which is safe for an open or for the close of a session that has already ended. Everything else, beta included, is computed on the chart's own bars.
Sürüm Notları
v2.2.0New input: Index source (Auto / Futures / Cash index).
The four series were always the continuous futures, NQ1!, ES1!, YM1! and RTY1!. Those are the right series intraday, since the cash indexes have no overnight bars, but they are back-adjusted: every roll shifts the whole history by that contract's roll gap, and each of the four rolls by a different amount. Over a few weeks that is invisible. Over a long anchor such as the swing low a year back it moves each index's percent change by a few points, by a different few points per index, so the numbers are no longer the cash indexes' returns.
Cash index reads NDX, SPX, DJI and RUT instead: exact over any horizon, cash session only. Auto, the default, uses futures on intraday charts and cash on daily and above, which is where the long anchors live. The Ref cell's tooltip says which set is in use. Beta is fitted on whichever set is in use, so beta-adjusted mode stays consistent with the lines.
Existing charts get Auto, so a daily chart switches to the cash indexes on this update and its numbers move by a few points. Set Futures to keep the old series.
Sürüm Notları
v2.3.0Steam line indicator functionality and inputs to focus on Index lead/lag not conflate it with a symbol on the chart.
The chart symbol moves out to its own overlay, Symbol vs NQ [BMT]. Its column, the confirmed state, the regime profile and the chart tint asked a different question (is this name adding something beyond its NQ beta) against a different benchmark (NQ, not ES) on a scale the pane could not hold, and they had grown to a third of the inputs. Index Lead Lag is back to four indexes, one benchmark and one threshold. The new script shares the same anchors, so with both on a chart they measure from the same bar. Include chart symbol and Tint chart by symbol vs NQ are gone from this script; add Symbol vs NQ [BMT] for that read.
Ribbon tooltips. With the index lines off, hover any dot for its state and sigma on one line and the ranking on the next; in Leader mode, the leader and the spread against its average. The long reading stays on the triangles and in the table. The tooltips cover the bars on screen, up to 500 of them, and the dots themselves go on regardless.
Beta window removed as an input. It is now four anchor periods on the chart's own bars: four sessions for a session anchor, four months for a month anchor, four times the span for a swing or a date, floor 60 and cap 2000. A fixed 90 bars was a few hours on a 5m chart and four months on a daily one, and on a long anchor the beta's estimation error, times the size of the ES move, could outweigh the residual. The beta row's tooltip and the data window show the bars in use. A saved Beta window value is ignored on this update. This tightens the estimate over long anchors; it does not make a beta that has drifted over a year the right baseline, so raw mode is still the read for anchors months back.
Two measures gone. N sessions (the close N daily sessions ago) went unused; Prior close is the N=1 case and stays. Fixed date's "Anchor at current session" checkbox restated Session open, one bar worse (the first bar's close rather than the daily open), and existed only to make the stale default date usable; Fixed date now means the date picked, and a date before the loaded history anchors at the first bar loaded, which the Ref cell marks with !. Charts saved on N sessions fall back to Auto.
Sürüm Notları
v2.3.1Fixed: on daily and weekly charts of a stock, the cash indexes arrived one bar late. Their daily bars close after a stock's (NDX is calculated to 17:16 ET), and TradingView merges same-timeframe requests by close time, so every historical bar carried the index's previous close. The four lagged together, so the ranking and the betas held, but each period's first bar paired the index's prior close with the correct period open, and the swing extremes sat a bar late. The chart-timeframe requests now use lookahead on, which on the same timeframe is the bar's own close and nothing from the future. Measured on DELL, 2026-09-15. Futures and intraday charts were aligned before and are unchanged.
The Show status table switch is folded into the location picker, now titled Status table, as a Hidden entry. Charts that had the switch off show the table until Hidden is picked, since a removed setting cannot carry over.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.