OPEN-SOURCE SCRIPT
SW_WickSize

═════════════════════════════════════════════════════════════
// SW_UPPER/LOWER WICKSIZE — USER GUIDE
// ═════════════════════════════════════════════════════════════
//
// WHAT IT DOES
// Draws ONE box per bar, colored to match that bar's own candle color
// (green candle -> green box, red candle -> red box). Each box crosses
// a zero baseline: the part above zero is the rolling average of that
// color's upper wick, the part below is the rolling average of that
// color's lower wick.
//
// A bar where close == open (neither green nor red) draws no box.
//
// WICK DEFINITIONS
// Green upper wick = high - close Green lower wick = open - low
// Red upper wick = high - open Red lower wick = close - low
//
// AVERAGING
// Both colors' wick values are computed on every bar (0 on bars that
// don't match that color), then smoothed with a simple moving average
// over the last `x` bars. This means the average reflects both how
// large the wicks are AND how often that color occurs in the lookback
// window — fewer bars of a color in the window pulls its average down
// even if the bars that did occur had large wicks.
//
// BOX SIZE — REAL PRICE UNITS, NOT A PERCENTAGE
// Box height is the actual averaged wick length on the same price
// scale as the candles above, not a percentage or fraction of the bar.
//
// HOW THE BOX IS DRAWN (plotcandle, not box.new)
// The box is drawn using plotcandle() — Pine's native candle-shape
// plot — rather than box.new(). plotcandle(open, high, low, close)
// normally draws OHLC; here open=high=top value and close=low=bottom
// value, which collapses the "wick" to nothing and makes the "body"
// span exactly [bottom, top], giving a solid rectangle crossing zero.
// Using plotcandle guarantees the box aligns exactly under its own
// candle at every zoom level, since it shares the same native
// rendering pipeline as real candles (manual box.new() coordinates,
// whether time-based or index-based, cannot achieve this reliably).
//
// PLOTCANDLE STYLE-TAB NOTE
// plotcandle always exposes Body/Wick/Border as separate color pairs
// in the Style tab — this is a fixed platform behavior. We only use the
// Body color setting. Wick and Border color settings can be ignored.
//
// DOJI MARKER
// A yellow diamond is drawn exactly on the zero line whenever a
// candle's body is small relative to its full high-low range (default
// 5%). This is a visual flag only — it never affects bar
// classification or the wick averages. Drawn last so it renders above
// both the boxes and the zero line.
//
// LAYERING
// Draw order is: plotcandle (boxes) -> hline (zero line) -> plotshape
// (doji marker). Pine renders later plot-family calls on top of
// earlier ones, so the zero line sits above the boxes, and the doji
// diamond sits above everything.
//
// INPUTS
// x — lookback length for the averages (default 5)
// showGreenBox/showRedBox — per-color visibility toggle
// greenColor/redColor — box colors
// scaleHeadroomPts — additive invisible scale padding: adds a fixed
// number of points above the tallest recent bar
// to push the zero line further down in the
// pane. 0 = off.
// dojiBodyPct — doji threshold, as % of that bar's high-low
// range (default 5%)
// ════════════════════════════════════════════════════════════
// SW_UPPER/LOWER WICKSIZE — USER GUIDE
// ═════════════════════════════════════════════════════════════
//
// WHAT IT DOES
// Draws ONE box per bar, colored to match that bar's own candle color
// (green candle -> green box, red candle -> red box). Each box crosses
// a zero baseline: the part above zero is the rolling average of that
// color's upper wick, the part below is the rolling average of that
// color's lower wick.
//
// A bar where close == open (neither green nor red) draws no box.
//
// WICK DEFINITIONS
// Green upper wick = high - close Green lower wick = open - low
// Red upper wick = high - open Red lower wick = close - low
//
// AVERAGING
// Both colors' wick values are computed on every bar (0 on bars that
// don't match that color), then smoothed with a simple moving average
// over the last `x` bars. This means the average reflects both how
// large the wicks are AND how often that color occurs in the lookback
// window — fewer bars of a color in the window pulls its average down
// even if the bars that did occur had large wicks.
//
// BOX SIZE — REAL PRICE UNITS, NOT A PERCENTAGE
// Box height is the actual averaged wick length on the same price
// scale as the candles above, not a percentage or fraction of the bar.
//
// HOW THE BOX IS DRAWN (plotcandle, not box.new)
// The box is drawn using plotcandle() — Pine's native candle-shape
// plot — rather than box.new(). plotcandle(open, high, low, close)
// normally draws OHLC; here open=high=top value and close=low=bottom
// value, which collapses the "wick" to nothing and makes the "body"
// span exactly [bottom, top], giving a solid rectangle crossing zero.
// Using plotcandle guarantees the box aligns exactly under its own
// candle at every zoom level, since it shares the same native
// rendering pipeline as real candles (manual box.new() coordinates,
// whether time-based or index-based, cannot achieve this reliably).
//
// PLOTCANDLE STYLE-TAB NOTE
// plotcandle always exposes Body/Wick/Border as separate color pairs
// in the Style tab — this is a fixed platform behavior. We only use the
// Body color setting. Wick and Border color settings can be ignored.
//
// DOJI MARKER
// A yellow diamond is drawn exactly on the zero line whenever a
// candle's body is small relative to its full high-low range (default
// 5%). This is a visual flag only — it never affects bar
// classification or the wick averages. Drawn last so it renders above
// both the boxes and the zero line.
//
// LAYERING
// Draw order is: plotcandle (boxes) -> hline (zero line) -> plotshape
// (doji marker). Pine renders later plot-family calls on top of
// earlier ones, so the zero line sits above the boxes, and the doji
// diamond sits above everything.
//
// INPUTS
// x — lookback length for the averages (default 5)
// showGreenBox/showRedBox — per-color visibility toggle
// greenColor/redColor — box colors
// scaleHeadroomPts — additive invisible scale padding: adds a fixed
// number of points above the tallest recent bar
// to push the zero line further down in the
// pane. 0 = off.
// dojiBodyPct — doji threshold, as % of that bar's high-low
// range (default 5%)
// ════════════════════════════════════════════════════════════
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.