OPEN-SOURCE SCRIPT

Pivot Rays [BMT]

617
Pivot Rays [BMT]

Horizontal rays from every pivot high and low that price has not yet taken out, on the chart timeframe and up to three higher ones, tagged by timeframe, plus the all-time high. Only the levels inside the price range on screen are drawn, so the rays never stretch the chart's auto-scale, and a level disappears the moment price trades through it.

What it draws

A pivot high is a bar whose high is not exceeded by any of the N bars to its left or right (N is the Bars left / right input, 5 by default); a pivot low is the mirror. Each confirmed pivot becomes a horizontal ray from the bar that made it to the right edge of the chart.

The rays are rebuilt on every tick of the last bar from a stored list of pivots, so what you see is always the current set: rays appear as price approaches a level or as you scroll it into view, and leave when the level is broken or scrolls out.

Timeframes

Four rows: the chart timeframe and three higher ones, preset to 4H, D and W. Each row has its own on/off switch, timeframe, tag and line width. A row whose timeframe is not above the chart's is ignored; a row equal to the chart's lends its tag to the chart pivots instead, so a daily chart still prints D on its own pivots. Chart-timeframe pivots carry no tag by default; give the row a tag if you want one.

Pivots at the same price on several timeframes are one level, not three: they merge into a single ray whose tag lists every timeframe it belongs to, for example "D 4H". The merged ray starts at the bar of the lowest timeframe in the group, because that is the exact bar: a daily pivot is only known to the resolution of the daily bar, and on a 5-minute chart that is the day's open, hours before the candle that actually made the high. A merge tolerance in ticks (0 by default) widens what counts as the same price.

Which pivots are drawn

Three modes.

  • Visible price range (default): only levels between the lowest low and highest high of the bars currently on screen. The range is measured from the bars alone, never from the drawings, so nothing is ever drawn outside the candles' own span and Reset chart view fits the candles rather than a distant level. The set follows every scroll and zoom.
  • Within N ATR: levels within N chart-timeframe ATRs of the current close (ATR(14) x 5 by default), whether on screen or not. Higher-timeframe pivots are measured against the same chart ATR.
  • Both: on screen and near price.


A cap on the number of rays keeps the nearest to price when more than that pass the filter.

Broken pivots

A pivot is broken when price trades through it: a wick beyond the level by default, or a close beyond it by input (the close test runs on bar close only, so a live bar does not flicker). A broken pivot is removed. Because every break removes a level, the stored set holds only the pivots price has never taken out, the staircase of highs above and lows below, and stays small however long the chart is.

The most recent break stays on as a dashed, fainter ray so the level just lost or reclaimed is still in view, and is dropped at the close of the period it happened in, daily by default: a level taken out during Tuesday's session shows dashed through Tuesday and is gone at the daily close. On a chart at or above that timeframe it lasts for the break bar only. The count is of break events, not pivots, so every pivot broken by the same bar stays or goes together. Both the expiry timeframe and how many recent breaks to keep are inputs; the dashed ray can be turned off.

All-time high

Its own dotted, heavier ray tagged ATH. The value comes from the symbol's monthly series, which TradingView serves back to the first bar it has for the symbol whatever the chart timeframe, combined with the loaded bars for the open month, so it is the real all-time high on a 5-minute chart, not the high of the bars loaded. On a continuous futures symbol it is the high of that continuous series, adjusted or not as the chart is set. Loaded bars is available as an alternative source. The ATH obeys the same filter as the pivots by default, so it shows when you scroll or zoom out far enough to include it; an input draws it always. A pivot high at the ATH price is left to the ATH ray rather than drawn twice.

Labels

A tag at the pivot bar by default, above a high or below a low (the empty side, by definition of a pivot), so it lands in the same place at any zoom. Right edge hangs the tag from an anchor a settable number of bars past the last bar; that number has to match the chart's right margin, which is a pixel width and so a different number of bars at every zoom. Text size, and whether the price is appended, are inputs. Each tag's tooltip gives the timeframes and the pivot's date.

Theme

Auto reads the chart background and picks the muted text gray of the light or dark theme for the rays, at a default 30% transparency so they sit behind the candles, with the theme's primary text color for the tags. The dashed broken ray is fainter by a settable amount. Custom exposes the ray, ATH and label colors.

Notes

Higher-timeframe pivots are one request.security call per row, asking for the previous higher-timeframe bar's pivot with lookahead on. That is the standard non-repainting form: a pivot is stored once the higher-timeframe bar that confirms it has closed, and never changes afterwards. Chart-timeframe pivots confirm N bars after the pivot bar, as pivots do. The ATH is one more request on the monthly series.

Because the chart timeframe's pivots are stored from the bars loaded on the chart, a higher-timeframe pivot older than the chart's first bar is drawn from the left edge, with its true date in the tooltip.

Exención de responsabilidad

La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.