OPEN-SOURCE SCRIPT
Index Peak Dispersion

█ OVERVIEW
Index Peak Dispersion plots, in a separate pane, two normalized series computed across a configurable universe of up to twelve equity indexes: the calendar-day dispersion of their all-time-high dates, expressed as a percent of a topping window, and the share of indexes that printed a fresh all-time high within a short recent window. The thesis is that healthy advances register all-time highs across indexes nearly simultaneously, while major distributive tops fragment, spreading index peak dates across weeks or months.
█ HISTORY / BACKGROUND
The concept descends from the non-confirmation principle of Dow Theory as developed by Charles Dow, William Hamilton and Robert Rhea, in which a new high in one average unaccompanied by a new high in another warns that the trend is losing sponsorship. Classic non-confirmation is measured in the price domain: one index fails to exceed its prior peak while another does.
Market historians and technicians, including Robert Prechter, have documented a related phenomenon in the time domain: at major tops, the final all-time highs of the major indexes scatter across the calendar rather than clustering. At the 2000 top, the Dow Industrials peaked in January, the S&P 500 and NASDAQ Composite in March, and the NYSE Composite in September. At the 2007 top, the Dow Jones Composite peaked in July while the Dow Industrials and S&P 500 peaked in October. This script converts that qualitative observation into a mechanical, reproducible statistic.
█ HOW IT WORKS
The script performs the following steps on each bar:
• For each of up to twelve enabled symbols, one same-timeframePine Script® call evaluates a function inside the requested symbol's context. The function maintains a running maximum of closing prices over the symbol's loaded history and records the timestamp of the bar on which that maximum was last exceeded. This running maximum is point-in-time by construction: no future data enters the calculation, and lookahead is off.
• On the chart symbol, each recorded timestamp is converted to an age in calendar days: current bar time minus the all-time-high time, divided by the number of milliseconds in a day.
• Each enabled index with data is classified. An age at or below the fresh window makes it Fresh. An age at or below the topping window makes it part of the in-window set. An age beyond the topping window makes it Stale.
• When the in-window set contains at least the minimum required count of indexes, the dispersion span equals the maximum in-window age minus the minimum in-window age, in calendar days. The plotted dispersion value is that span divided by the topping window length, times 100. When the in-window count is below the minimum, the dispersion plot returns na.
• The participation value equals the count of Fresh indexes divided by the count of enabled indexes with data, times 100, plotted as columns.
• The fractured top condition is true when the dispersion value is at or above the warning threshold while at least one index is Fresh. The pane background is shaded on those bars, and an alert fires on the first bar of each new occurrence. A second alert fires when every enabled index with data is simultaneously Fresh, which marks a synchronized advance, the opposite condition.
• On the last bar, an optional table lists each index with its all-time-high date, age in days and classification, plus summary counts and the raw span in days.
█ HOW TO USE
The script is designed for the 1D timeframe. The running all-time high is intended to operate on daily closes, and both windows are specified in calendar days, so daily resolution matches the granularity of the logic.
In plain terms, the blue columns answer one question: how many of the enabled indexes hit a record high this week? The red line answers another: how spread out in time are everyone's record highs? In a strong market, the indexes peak together, so the columns are tall and the line stays low. At major tops, the market tends to fall apart in slow motion: one index peaks, then months later another, and by the time the last index prints its final record, several others stopped making records long ago. Each new high is carried by fewer indexes, so the columns thin out while the line climbs. The shaded background marks the combination of both: the market is still printing record highs, but the set of indexes confirming them has been shrinking for months. That is the structure documented at the 2000 and 2007 tops. The same combination also appears during rotation phases that resolve higher, so treat it as a statement that conditions resemble past major tops, not as an instruction to act.
Read the two plotted series together. Low dispersion with high participation describes a synchronized advance in which the enabled indexes are registering highs together. Rising dispersion while some indexes continue to print fresh highs describes fragmentation: leadership is narrowing and earlier leaders have stopped confirming. The shaded background marks bars on which the dispersion value is at or above the dashed threshold line while at least one fresh high exists, the specific combination in which fragmentation is present at a live high rather than in an established downtrend.
The table gives the attribution behind the numbers: which indexes are Fresh, which remain inside the topping window, and which have gone Stale, along with each all-time-high date. Stale entries are non-confirmations older than the topping window and are deliberately excluded from the span so that a single long-dormant index does not saturate the statistic.
The condition is a warning context, not a timing trigger. It identifies an environment consistent with historical distributive tops. It does not predict the date or the existence of a decline.
█ SETTINGS
• Index universe, twelve slots, each with an enable checkbox and a symbol field. Defaults: DJI, DJT, DJU, DJA, SPX, NDX, IXIC, NYA, RUT, SOX, MID, SPXEW. All twelve are enabled by default. Any slot can be repointed to another symbol or disabled.
• Fresh high window, calendar days. Default 7. An index whose all-time high printed within this many days counts as Fresh.
• Topping window, calendar days. Default 378. An index whose all-time high printed within this many days participates in the dispersion span. Older highs are classified Stale.
• Dispersion warning threshold, percent of topping window. Default 25. The dashed reference line and the threshold for the fractured top condition.
• Minimum in-window index count for a valid span. Default 4. Below this count the dispersion plot returns na, which prevents a span computed from too few indexes.
• Show status table. Default on.
• Table position. Default Top right.
█ WHAT MAKES IT ORIGINAL
Breadth and non-confirmation tools on this platform generally measure the price domain: divergences between an index and an internal line, counts of components above a moving average, or new-high and new-low tallies within one exchange universe. This script instead measures the time domain across whole indexes. It reduces the peak-date scatter of a user-defined index universe to a single bounded statistic, the in-window span of all-time-high ages, and pairs it with a participation series so that fragmentation is only flagged while a high is live. The classification into Fresh, in-window and Stale, with the Stale exclusion and the minimum-count validity gate, is what allows the scatter of a historical topping process to be plotted as one continuous, comparable series across eras.
█ NOTES / LIMITATIONS
• The running all-time high is computed only over the bars loaded for each requested symbol. Symbols with short available history, and the early portion of any chart, understate the true age of the all-time high. Treat the plot as reliable only after all enabled symbols have substantial loaded history.
• The logic is designed for the 1D timeframe. On intraday charts the running maximum operates on intraday closes and the calendar-day windows lose their intended granularity. On weekly or monthly charts a fresh window shorter than one bar cannot register.
• AllPine Script® calls run on the chart timeframe with lookahead off. Values on the developing bar update until the bar closes and do not repaint afterward.
• The script issues twelve security calls. A symbol slot that fails to resolve or returns no data is excluded from every count and appears in the table as No data.
• Ages and spans are measured in calendar days, not trading days, so weekends and holidays are included in the counts.
• The warning threshold is expressed as a percent of the topping window. Changing the topping window changes the day-equivalent of the same percent threshold.
• The dispersion plot returns na whenever fewer than the minimum required indexes have an all-time high inside the topping window.
• The status table renders on the last bar only.
Index Peak Dispersion plots, in a separate pane, two normalized series computed across a configurable universe of up to twelve equity indexes: the calendar-day dispersion of their all-time-high dates, expressed as a percent of a topping window, and the share of indexes that printed a fresh all-time high within a short recent window. The thesis is that healthy advances register all-time highs across indexes nearly simultaneously, while major distributive tops fragment, spreading index peak dates across weeks or months.
█ HISTORY / BACKGROUND
The concept descends from the non-confirmation principle of Dow Theory as developed by Charles Dow, William Hamilton and Robert Rhea, in which a new high in one average unaccompanied by a new high in another warns that the trend is losing sponsorship. Classic non-confirmation is measured in the price domain: one index fails to exceed its prior peak while another does.
Market historians and technicians, including Robert Prechter, have documented a related phenomenon in the time domain: at major tops, the final all-time highs of the major indexes scatter across the calendar rather than clustering. At the 2000 top, the Dow Industrials peaked in January, the S&P 500 and NASDAQ Composite in March, and the NYSE Composite in September. At the 2007 top, the Dow Jones Composite peaked in July while the Dow Industrials and S&P 500 peaked in October. This script converts that qualitative observation into a mechanical, reproducible statistic.
█ HOW IT WORKS
The script performs the following steps on each bar:
• For each of up to twelve enabled symbols, one same-timeframe
• On the chart symbol, each recorded timestamp is converted to an age in calendar days: current bar time minus the all-time-high time, divided by the number of milliseconds in a day.
• Each enabled index with data is classified. An age at or below the fresh window makes it Fresh. An age at or below the topping window makes it part of the in-window set. An age beyond the topping window makes it Stale.
• When the in-window set contains at least the minimum required count of indexes, the dispersion span equals the maximum in-window age minus the minimum in-window age, in calendar days. The plotted dispersion value is that span divided by the topping window length, times 100. When the in-window count is below the minimum, the dispersion plot returns na.
• The participation value equals the count of Fresh indexes divided by the count of enabled indexes with data, times 100, plotted as columns.
• The fractured top condition is true when the dispersion value is at or above the warning threshold while at least one index is Fresh. The pane background is shaded on those bars, and an alert fires on the first bar of each new occurrence. A second alert fires when every enabled index with data is simultaneously Fresh, which marks a synchronized advance, the opposite condition.
• On the last bar, an optional table lists each index with its all-time-high date, age in days and classification, plus summary counts and the raw span in days.
█ HOW TO USE
The script is designed for the 1D timeframe. The running all-time high is intended to operate on daily closes, and both windows are specified in calendar days, so daily resolution matches the granularity of the logic.
In plain terms, the blue columns answer one question: how many of the enabled indexes hit a record high this week? The red line answers another: how spread out in time are everyone's record highs? In a strong market, the indexes peak together, so the columns are tall and the line stays low. At major tops, the market tends to fall apart in slow motion: one index peaks, then months later another, and by the time the last index prints its final record, several others stopped making records long ago. Each new high is carried by fewer indexes, so the columns thin out while the line climbs. The shaded background marks the combination of both: the market is still printing record highs, but the set of indexes confirming them has been shrinking for months. That is the structure documented at the 2000 and 2007 tops. The same combination also appears during rotation phases that resolve higher, so treat it as a statement that conditions resemble past major tops, not as an instruction to act.
Read the two plotted series together. Low dispersion with high participation describes a synchronized advance in which the enabled indexes are registering highs together. Rising dispersion while some indexes continue to print fresh highs describes fragmentation: leadership is narrowing and earlier leaders have stopped confirming. The shaded background marks bars on which the dispersion value is at or above the dashed threshold line while at least one fresh high exists, the specific combination in which fragmentation is present at a live high rather than in an established downtrend.
The table gives the attribution behind the numbers: which indexes are Fresh, which remain inside the topping window, and which have gone Stale, along with each all-time-high date. Stale entries are non-confirmations older than the topping window and are deliberately excluded from the span so that a single long-dormant index does not saturate the statistic.
The condition is a warning context, not a timing trigger. It identifies an environment consistent with historical distributive tops. It does not predict the date or the existence of a decline.
█ SETTINGS
• Index universe, twelve slots, each with an enable checkbox and a symbol field. Defaults: DJI, DJT, DJU, DJA, SPX, NDX, IXIC, NYA, RUT, SOX, MID, SPXEW. All twelve are enabled by default. Any slot can be repointed to another symbol or disabled.
• Fresh high window, calendar days. Default 7. An index whose all-time high printed within this many days counts as Fresh.
• Topping window, calendar days. Default 378. An index whose all-time high printed within this many days participates in the dispersion span. Older highs are classified Stale.
• Dispersion warning threshold, percent of topping window. Default 25. The dashed reference line and the threshold for the fractured top condition.
• Minimum in-window index count for a valid span. Default 4. Below this count the dispersion plot returns na, which prevents a span computed from too few indexes.
• Show status table. Default on.
• Table position. Default Top right.
█ WHAT MAKES IT ORIGINAL
Breadth and non-confirmation tools on this platform generally measure the price domain: divergences between an index and an internal line, counts of components above a moving average, or new-high and new-low tallies within one exchange universe. This script instead measures the time domain across whole indexes. It reduces the peak-date scatter of a user-defined index universe to a single bounded statistic, the in-window span of all-time-high ages, and pairs it with a participation series so that fragmentation is only flagged while a high is live. The classification into Fresh, in-window and Stale, with the Stale exclusion and the minimum-count validity gate, is what allows the scatter of a historical topping process to be plotted as one continuous, comparable series across eras.
█ NOTES / LIMITATIONS
• The running all-time high is computed only over the bars loaded for each requested symbol. Symbols with short available history, and the early portion of any chart, understate the true age of the all-time high. Treat the plot as reliable only after all enabled symbols have substantial loaded history.
• The logic is designed for the 1D timeframe. On intraday charts the running maximum operates on intraday closes and the calendar-day windows lose their intended granularity. On weekly or monthly charts a fresh window shorter than one bar cannot register.
• All
• The script issues twelve security calls. A symbol slot that fails to resolve or returns no data is excluded from every count and appears in the table as No data.
• Ages and spans are measured in calendar days, not trading days, so weekends and holidays are included in the counts.
• The warning threshold is expressed as a percent of the topping window. Changing the topping window changes the day-equivalent of the same percent threshold.
• The dispersion plot returns na whenever fewer than the minimum required indexes have an all-time high inside the topping window.
• The status table renders on the last bar only.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。