Skip to content

Pine Script

ta.pivothigh() in Pine Script: Pivot Lows and Repainting

ta.pivothigh() in Pine Script identifies a local high using a specified number of bars on its left and right; ta.pivotlow() identifies a local low. A pivot becomes knowable only after its right-hand bars develop, and a stable signal waits for the final confirming bar to close. Plotting that result back on the pivot bar changes its display location, not when it was available.

Illustrative pivot cover showing a local high and a separate confirmation marker two bars later.
The pivot bar and the bar that confirms it are different points in time.

ta.pivothigh() and ta.pivotlow() at a glance

As of 25 September 2026, the Pine Script v6 Reference Manual defines these functions and their overloads.[1] TradingView's repainting guide explains the separate risk of drawing their results into the past.[2]

Scroll horizontally to read every column.

Item Meaning
leftbars Number of bars before the candidate used to establish the pivot.
rightbars Number of bars after the candidate needed to detect the pivot.
Return value The pivot price when detected, otherwise na.
Source Optional first argument in the three-argument overload; the sketch below passes high and low explicitly.
Negative plot offset Moves the drawing left. It does not move an alert back in time.
Trading rule A pivot price alone does not define an entry, exit or market-structure break.

The Pine Script library covers the execution model behind these functions. Here, “pivot” means a local swing point, rather than a separate session-based Pivot Points indicator.

What are the pivot function signatures?

ta.pivothigh(leftbars, rightbars) or ta.pivothigh(source, leftbars, rightbars)

ta.pivotlow(leftbars, rightbars) or ta.pivotlow(source, leftbars, rightbars)

Both return a series float. The two-argument forms take no source argument; the three-argument forms let the script supply one. Passing high or low explicitly avoids relying on an implied default. A result is a price, so use not na(result) to detect its presence rather than treating the number as a boolean.[1] TradingView uses that presence check in its pivot examples.[3]

For fixed, positive left and right lengths, the timing relationship is:

Detection bar index = pivot bar index + rightbars
Inspection window = leftbars + 1 + rightbars

The middle bar is the candidate. The right-hand portion supplies information that did not exist at the candidate's close. Waiting for that information is a definition of the calculation, not an execution delay introduced by an alert service.[2]

Worked example: why a pivot needs two more bars

Illustrative values, not recommended settings. Set leftbars = 2 and rightbars = 2. Five consecutive bars have the following highs. The example has no equal highs, so it does not depend on a tie convention.

Bar index High Role
8 100 First left bar
9 102 Second left bar
10 110 Candidate pivot high
11 106 First right bar
12 104 Second right bar

The inspection window is 2 + 1 + 2 = five bars. The function reports the pivot price, 110, on bar 10 + 2 = 12. If bar 12 is still open, its high could rise above 110 and invalidate that candidate. The confirmed event therefore belongs at bar 12's close.

On consecutive 15-minute bars with no session gap, the delay from the pivot bar's close to the detection bar's close is 2 × 15 = 30 minutes. Plotting with offset = -2 places the marker at bar 12 − 2 = 10, but the information still arrived on bar 12.

A separate low example follows the same timing: lows of 102, 100, 90, 94 and 96 identify the middle price, 90, only on the fifth bar. Neither example is a trade signal without an additional rule.

Illustrative pivot timing: a high of 110 at bar 10 is confirmed at bar 12 after two right-hand bars; a negative plot offset moves only the drawing.
Illustrative values. Log both the pivot's origin bar and the later bar that made the pivot knowable.

Is pivot confirmation the same as repainting?

The confirmation delay itself does not revise a previously confirmed pivot. The candidate was simply not confirmed yet. However, TradingView uses a broader definition of repainting: historical and realtime calculations or plots behave differently.[2]

Under that definition, drawing a newly detected pivot on an earlier bar is repainting. A bar that previously displayed no pivot now gains one. TradingView explicitly describes this under “Plotting in the past” and shows a display option that makes the backdating visible to the user.[2]

Keep three cases separate: a candidate awaiting right-hand bars, a provisional result during the detection bar, and a confirmed result drawn in the past. Calling all three either “non-repainting” or “fake” hides the useful timing distinction.

How do you plot pivots and alert at the correct time?

The following indicator defaults to drawing on the detection bar. Its optional negative offset changes only the drawing. The event conditions require barstate.isconfirmed, so an unfinished detection bar cannot trigger these conditions.[1][2]

Illustrative sketch; not compiled or tested. Paste into the TradingView Pine Editor. The two-bar lengths illustrate the worked example, not preferred settings.

//@version=6
indicator("Pivot detection time", overlay = true)
left = 2
right = 2
backdate = input.bool(false, "Draw on the earlier pivot bar")
ph = ta.pivothigh(high, left, right)
pl = ta.pivotlow(low, left, right)
highReady = barstate.isconfirmed and not na(ph)
lowReady = barstate.isconfirmed and not na(pl)
plot(highReady ? ph : na, "High", style = plot.style_circles, offset = backdate ? -right : 0)
plot(lowReady ? pl : na, "Low", style = plot.style_circles, offset = backdate ? -right : 0)
alertcondition(highReady, "Pivot high confirmed", "Pivot high confirmed")
alertcondition(lowReady, "Pivot low confirmed", "Pivot low confirmed")

alertcondition() supplies selectable indicator conditions; it does not create a running alert. In TradingView's Create Alert dialog, choose the required pivot condition and Once Per Bar Close. Historical detections do not send retrospective alerts.[4] The alertcondition() versus alert() guide explains the message and frequency differences.

The sketch's messages are plain notifications. A PineConnector instruction needs a separately defined action and a complete message in the documented syntax.[5] A pivot high does not inherently mean buy, sell or close.

What does confirmation change for SMC structure detection?

A script that uses swing points to define market structure needs an explicit rule for which confirmed pivot becomes its reference. For example, a developer might define a structure break as a close above the last confirmed pivot high. That is an illustrative specification, not a claim about where price will go.

  • Store two times: the pivot's origin and its confirmation. A historical annotation needs both to explain when a structure level became available.
  • Define a break: wick crossing, bar-close crossing and a close remaining above a level are different conditions.
  • Define replacement: a new confirmed high can replace a previous high even if no low appeared between them. TradingView's alternating-pivot example adds separate state to enforce a high-low sequence.[3]
  • Define equality: include equal-high and equal-low cases in the implementation checks rather than relying on a visually obvious swing.

The SMC and ICT concepts as rules guide develops those definitions. A level drawn on bar 10 must not be treated as an available input on bar 10 if its detection required bar 12.

What should you check before using pivot alerts?

Check the detection event against the live alert log, not only the backdated marker. A higher-timeframe pivot introduces another context; review request.security() and lookahead before assuming chart-bar confirmation also confirms the requested data.[2]

For a PineConnector demo, separate the true condition, alert trigger, webhook delivery, PineConnector processing and EA request. Then inspect broker acceptance, the deal and resulting position. PineConnector's test guide requires processing and broker-account checks separately.[6] MT5 distinguishes orders, deals and positions.[7]

Frequently asked questions

How does ta.pivothigh() work in Pine Script?

ta.pivothigh() checks a candidate against the specified number of left-hand and right-hand bars and returns its price when a pivot high is detected. Otherwise it returns na. The result appears on the detection bar, which is rightbars bars after the candidate. A stable alert waits for that detection bar to close.

Does ta.pivotlow() repaint?

A pivot low needs later bars before it can be confirmed, and a provisional result can change while the last confirming bar is open. Drawing a confirmed result back on its origin bar also changes the earlier display. TradingView classifies plotting into the past as repainting, even though the confirmation delay itself is expected.

Does a negative plot offset make a pivot alert earlier?

No. A negative plot offset changes where the marker is drawn, not when the pivot is calculated or the alert condition becomes true. With rightbars = 2, a pivot at bar 10 is detected at bar 12. An offset of −2 draws it at bar 10 without moving the alert there.

Are ta.pivothigh() and ta.pivotlow() complete market-structure signals?

No. The functions return local pivot prices. A market-structure rule must separately define which confirmed pivot matters, whether a wick or closing price constitutes a break, and how repeated or equal levels are handled. Drawing a pivot at an earlier bar does not make that level available to an earlier decision.

Reviewed 25 September 2026. Facts were checked against the linked sources on that date. Nothing in this article was tested on a trading account and no code was compiled.

Related reading

Sources

  1. TradingView – Pine Script v6 Reference Manual, accessed 25 September 2026.
  2. TradingView – Repainting: plotting in the past, accessed 25 September 2026.
  3. TradingView – Techniques: alternating pivot states, accessed 25 September 2026.
  4. TradingView – Alerts, accessed 25 September 2026.
  5. PineConnector – PineConnector Syntax, accessed 25 September 2026.
  6. PineConnector – Test your setup, accessed 25 September 2026.
  7. MetaQuotes – Basic principles: orders, deals and positions, accessed 25 September 2026.

PineConnector executes the instructions you send it. It does not select trades, manage money, or hold funds. Trading carries risk, and past performance of any strategy does not indicate future results.


Leave a comment

Back To PiCo Blog

Ready when your strategy is

You bring the strategy.We bring the infrastructure.

Connect TradingView to MetaTrader, choose where MT5 runs and put the full PineConnector workflow through its paces from your first month.

Strategy and trading decisions remain yours. The MT5 environment can be ours.

PineConnector Edge

Run the full PineConnector workflow.

$59/mo at launch

Core plan · 1 connection · 1 hosted MT5 environment

Try Core for $7

7 days of Core for $7, then $59/month at the launch price unless you cancel.