OPEN-SOURCE SCRIPT
O'Neil Climax Top Detector

█ OVERVIEW
O'Neil Climax Top Detector plots the percentage distance of a price source from its simple moving average in a separate pane and flags the bars where three conditions associated with a climax top occur together: the price is extended into an upper band, it has run up rapidly over a short window, and the bar carries record volume. The histogram measures extension; the flag identifies where extension, runup, and volume coincide.
█ HISTORY / BACKGROUND
The components are drawn from William J. O'Neil's discussion of climax (blow-off) tops in How to Make Money in Stocks. O'Neil described a stock trading 70% to 100% or more above its 200-day moving average line (4th edition, page 264), a rapid price runup over roughly two to three weeks, and heavy volume on the advance as markers of a late-stage move. O'Neil presented these as qualitative, infrequently decisive sell pointers for individual growth leaders on the daily chart, not as a mechanical signal. This script operationalizes that description as a single bar-level test.
█ HOW IT WORKS
On the chart timeframe the script computes, for each bar:
- The distance from the average: the simple moving average of the source over SMA Length, then percentage distance as (source minus average) divided by average, times 100. This is the histogram.
- The extension condition: the distance is at or above the lower band. In fixed mode the band is the Fixed lower / upper band inputs (70 and 100). In adaptive mode the band is the symbol's own mean distance plus a number of standard deviations (Adaptive lower / upper) over Adaptive lookback.
- The runup condition: the source's percentage gain over Runup lookback bars is at or above Min runup over lookback.
- The volume condition: the bar's volume is a new high over Volume record lookback bars. When Require record-volume condition is off, this term is dropped.
A climax bar is the conjunction of all active conditions:
Pine Script®
Climax bars are recolored on the histogram and marked with a vertical line spanning the pane. Two alert conditions are exposed: one for the full climax conjunction, one for the distance reaching the lower band.
█ HOW TO USE
Apply on the daily chart, the resolution on which O'Neil's band and runup window are defined. Read the histogram as the degree of extension above or below the average: bars above zero trade above the average, bars below zero trade below it. The lower and upper band lines bound the extension zone. A recolored bar with a vertical line marks where extension, runup, and volume align on the same bar. Treat a flag as a candidate for review of a late-stage move, not as an instruction.
█ SETTINGS
- Source: series used for the average and the distance. Default close.
- SMA Length: period of the simple moving average. Default 200.
- Extension band mode: fixed O'Neil 70/100 band, or per-symbol adaptive band. Default fixed.
- Fixed lower / upper band: the band in fixed mode. Defaults 70 and 100.
- Adaptive lookback: window for the adaptive band statistics. Default 504.
- Adaptive lower / upper: standard deviations above the mean distance defining the adaptive band. Defaults 2.0 and 3.0.
- Runup lookback: bars over which the runup is measured. Default 10.
- Min runup over lookback: minimum percentage gain to satisfy the runup. Default 25.
- Require record-volume condition: include the volume term. Default on.
- Volume record lookback: window over which the bar's volume must be the highest. Default 50.
█ WHAT MAKES IT ORIGINAL
A plain distance-from-moving-average histogram only shows extension. This script requires extension, a rapid runup, and record volume to coincide on the same bar before it flags, which is the conjunction O'Neil described qualitatively but is not present in a single distance plot. The adaptive band is a further departure: O'Neil's 70 to 100 figure is calibrated to growth leaders and is rarely reached on indices or low-volatility instruments, so the script can replace the fixed band with one derived from the symbol's own distance distribution, extending the concept beyond the instrument class it was written for.
█ NOTES / LIMITATIONS
- Insufficient history: the average needs SMA Length bars, the adaptive band needs Adaptive lookback bars, and the runup needs Runup lookback bars. Until those windows fill, the corresponding output is na and no flag appears.
- Volume-free symbols: on instruments without volume the record-volume term resolves to na and nothing flags. Turning off Require record-volume condition runs the extension and runup pair only, a weaker two-condition test.
- Timeframe: the default band and runup window reflect O'Neil's daily-chart definition. On other resolutions the thresholds keep their numeric values but lose their reference meaning.
- Symbol class: the fixed band reflects individual growth-stock behavior. Use adaptive mode for indices, large-cap averages, and low-volatility instruments.
- Real-time bars: conditions confirm on bar close. On the forming bar a flag and its line can appear and disappear as price and volume change until the bar closes. Historical flags do not change.
- No higher-timeframe data: all computation is on the chart timeframe with no request.security and no lookahead.
- Object ceiling: the script retains up to 500 vertical lines. On long histories the oldest markers are dropped as new ones are added.
- The default thresholds are conceptual settings consistent with O'Neil's description, not optimized or validated values.
O'Neil Climax Top Detector plots the percentage distance of a price source from its simple moving average in a separate pane and flags the bars where three conditions associated with a climax top occur together: the price is extended into an upper band, it has run up rapidly over a short window, and the bar carries record volume. The histogram measures extension; the flag identifies where extension, runup, and volume coincide.
█ HISTORY / BACKGROUND
The components are drawn from William J. O'Neil's discussion of climax (blow-off) tops in How to Make Money in Stocks. O'Neil described a stock trading 70% to 100% or more above its 200-day moving average line (4th edition, page 264), a rapid price runup over roughly two to three weeks, and heavy volume on the advance as markers of a late-stage move. O'Neil presented these as qualitative, infrequently decisive sell pointers for individual growth leaders on the daily chart, not as a mechanical signal. This script operationalizes that description as a single bar-level test.
█ HOW IT WORKS
On the chart timeframe the script computes, for each bar:
- The distance from the average: the simple moving average of the source over SMA Length, then percentage distance as (source minus average) divided by average, times 100. This is the histogram.
- The extension condition: the distance is at or above the lower band. In fixed mode the band is the Fixed lower / upper band inputs (70 and 100). In adaptive mode the band is the symbol's own mean distance plus a number of standard deviations (Adaptive lower / upper) over Adaptive lookback.
- The runup condition: the source's percentage gain over Runup lookback bars is at or above Min runup over lookback.
- The volume condition: the bar's volume is a new high over Volume record lookback bars. When Require record-volume condition is off, this term is dropped.
A climax bar is the conjunction of all active conditions:
Climax bars are recolored on the histogram and marked with a vertical line spanning the pane. Two alert conditions are exposed: one for the full climax conjunction, one for the distance reaching the lower band.
█ HOW TO USE
Apply on the daily chart, the resolution on which O'Neil's band and runup window are defined. Read the histogram as the degree of extension above or below the average: bars above zero trade above the average, bars below zero trade below it. The lower and upper band lines bound the extension zone. A recolored bar with a vertical line marks where extension, runup, and volume align on the same bar. Treat a flag as a candidate for review of a late-stage move, not as an instruction.
█ SETTINGS
- Source: series used for the average and the distance. Default close.
- SMA Length: period of the simple moving average. Default 200.
- Extension band mode: fixed O'Neil 70/100 band, or per-symbol adaptive band. Default fixed.
- Fixed lower / upper band: the band in fixed mode. Defaults 70 and 100.
- Adaptive lookback: window for the adaptive band statistics. Default 504.
- Adaptive lower / upper: standard deviations above the mean distance defining the adaptive band. Defaults 2.0 and 3.0.
- Runup lookback: bars over which the runup is measured. Default 10.
- Min runup over lookback: minimum percentage gain to satisfy the runup. Default 25.
- Require record-volume condition: include the volume term. Default on.
- Volume record lookback: window over which the bar's volume must be the highest. Default 50.
█ WHAT MAKES IT ORIGINAL
A plain distance-from-moving-average histogram only shows extension. This script requires extension, a rapid runup, and record volume to coincide on the same bar before it flags, which is the conjunction O'Neil described qualitatively but is not present in a single distance plot. The adaptive band is a further departure: O'Neil's 70 to 100 figure is calibrated to growth leaders and is rarely reached on indices or low-volatility instruments, so the script can replace the fixed band with one derived from the symbol's own distance distribution, extending the concept beyond the instrument class it was written for.
█ NOTES / LIMITATIONS
- Insufficient history: the average needs SMA Length bars, the adaptive band needs Adaptive lookback bars, and the runup needs Runup lookback bars. Until those windows fill, the corresponding output is na and no flag appears.
- Volume-free symbols: on instruments without volume the record-volume term resolves to na and nothing flags. Turning off Require record-volume condition runs the extension and runup pair only, a weaker two-condition test.
- Timeframe: the default band and runup window reflect O'Neil's daily-chart definition. On other resolutions the thresholds keep their numeric values but lose their reference meaning.
- Symbol class: the fixed band reflects individual growth-stock behavior. Use adaptive mode for indices, large-cap averages, and low-volatility instruments.
- Real-time bars: conditions confirm on bar close. On the forming bar a flag and its line can appear and disappear as price and volume change until the bar closes. Historical flags do not change.
- No higher-timeframe data: all computation is on the chart timeframe with no request.security and no lookahead.
- Object ceiling: the script retains up to 500 vertical lines. On long histories the oldest markers are dropped as new ones are added.
- The default thresholds are conceptual settings consistent with O'Neil's description, not optimized or validated values.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.