PINE LIBRARY
Atualizado Pivot_Labels_Output_Utilities

This library contains reusable pivot label output helpers for Pine scripts that already have their own pivot, structure, or signal logic but want a shared label-rendering layer.
It centralizes the parts of the workflow that tend to get rewritten across label-heavy scripts: label-size resolution, compact percent and price formatting, one-shot pivot label plotting, live directional label management, confirmed/local/current-RSI text builders, early-label emoji output, and live-stack text / object helpers.
On the example chart, the visible label workflows are materially driven by the library, whether through the confirmed pivot label text, the local pivot label text, the current RSI + SMA above-bar label, the early directional labels, or the live stack text and label-object lifecycle helpers used to keep those outputs updated cleanly on the chart.
How to use
Import the library near the top of your script in global scope, alongside any other imports, before you start calling its helpers.
Typical placement:
// version=6
indicator(...) or strategy(...)
import MYNAMEISBRANDON/PivotLabelsOutput_Utilities/1 as PLutils
This library does not confirm pivots, resolve structure tags, or choose label colors for you. Instead, it expects your script to already know the values it wants to display, then uses those resolved inputs to build the output layer.
For more information on libraries and incorporating them into your scripts, see the Libraries section of the Pine Script User Manual.
➖Label Size Helpers➖
These helpers convert simple UI-facing size strings into Pine label-size enums so scripts can keep one consistent size resolver across confirmed pivot labels, local pivot labels, current RSI labels, early labels, and live stack labels.
labelSizeFromString(sizeIn)
Resolves a Pine label size from a string input.
Parameters:
sizeIn (simple string): Size string. Expected values: "Tiny", "Small", "Normal", "Large", or "Huge"
Returns:
Pine label size enum
➖Numeric Formatting Helpers➖
These helpers handle compact numeric formatting for label-driven scripts. They let a script calculate percent change safely, format that change in a label-friendly way, and convert larger price values into compact significant-figure style text.
labelPercentChange(curr, prev)
Returns percent change from prev to curr.
Parameters:
curr (float): Current value
prev (float): Previous reference value
Returns:
Percent change or na when invalid
labelFormatPercent(p)
Formats a percent value for compact label output.
Parameters:
p (float): Percent value
Returns:
Formatted percent string
labelFormatCompactNumber(x, sig)
Formats a number using significant-figure style suffix output.
Parameters:
x (float): Value to format
sig (simple int): Significant figures to preserve
Returns:
Compact number string
➖Static Label Plot Helpers➖
These helpers create one-shot label outputs for scripts that want to place confirmed or local pivot labels on historical pivot bars, or simple above-bar informational labels, without managing a live label object afterward.
plotPivotLabel(x, y, txt, textColor, isHigh, sizeIn)
Creates a pivot label on a specific bar.
Parameters:
x (int): Label x position
y (float): Label y position
txt (string): Label text
textColor (color): Label text color
isHigh (bool): True for a high-side label, false for a low-side label
sizeIn (simple string): Label size string
Returns:
Created label reference
plotAboveBarLabel(x, y, txt, textColor, sizeIn)
Creates an above-bar informational label.
Parameters:
x (int): Label x position
y (float): Label y position
txt (string): Label text
textColor (color): Label text color
sizeIn (simple string): Label size string
Returns:
Created label reference
➖Directional Label Object Helpers➖
These helpers manage the lifecycle of live high-side and low-side label objects so scripts can create, update, or delete directional labels without repeating the same object-management logic each time.
manageDirectionalLabel(lbl, show, x, y, txt, textColor, isHigh, sizeIn)
Creates, updates, or deletes a directional label object.
Parameters:
lbl (label): Existing label reference
show (bool): Whether the label should exist
x (int): Label x position
y (float): Label y position
txt (string): Label text
textColor (color): Label text color
isHigh (bool): True for a high-side label, false for a low-side label
sizeIn (simple string): Label size string
Returns:
Updated label reference
➖Pivot Text Helpers➖
These helpers build the final text used by confirmed pivot labels, local pivot labels, confirmed pivot alerts, and the current RSI / SMA above-bar label. In other words, this region keeps the script’s visible wording consistent while leaving structure resolution and color decisions to the calling script.
buildMajorPivotLabelText(mode, priceText, priceStruct, rsiText, oscStruct, percentText, pivotLen, showLen)
Builds confirmed pivot label text.
Parameters:
mode (simple string): Label mode. Expected values: "Full" or "RSI Only"
priceText (string): Formatted pivot price
priceStruct (string): Price-side structure tag
rsiText (string): Formatted pivot RSI
oscStruct (string): RSI-side structure tag
percentText (string): Formatted percent-change text
pivotLen (int): Pivot length value
showLen (bool): Whether pivot length should be shown
Returns:
Confirmed pivot label text
buildLocalPivotLabelText(priceText, priceStruct, rsiText, rsiStruct, pivotLen, showPrice, showLen)
Builds local pivot label text.
Parameters:
priceText (string): Formatted local pivot price
priceStruct (string): Price-side structure tag
rsiText (string): Formatted local pivot RSI
rsiStruct (string): RSI-side structure tag
pivotLen (int): Pivot length value
showPrice (bool): Whether the price line should be shown
showLen (bool): Whether pivot length should be shown
Returns:
Local pivot label text
buildPivotAlertText(isHigh, priceText, pctText, rsiText, structTag, rsiValue, rsiOB, rsiOS)
Builds confirmed pivot alert text.
Parameters:
isHigh (bool): True for a high pivot, false for a low pivot
priceText (string): Formatted pivot price
pctText (string): Formatted percent-change text
rsiText (string): Formatted pivot RSI
structTag (string): RSI-side structure tag
rsiValue (float): Raw RSI value at the pivot
rsiOB (int): Overbought level
rsiOS (int): Oversold level
Returns:
Alert message text
buildCurrentRsiAboveBarText(currRsiText, structTag, smaText)
Builds current RSI / SMA above-bar label text.
Parameters:
currRsiText (string): Formatted current RSI text
structTag (string): Current live structure tag
smaText (string): Formatted SMA text
Returns:
Current RSI above-bar label text
➖Early Pivot Label Helpers➖
These helpers provide the reusable output primitive used by early pivot labels. This region intentionally stops at emoji selection so scripts with different structure-tag models and color logic can still reuse the same active-vs-carried-forward label cue.
earlyPivotEmoji(isHigh, isCurrentCandidateBar)
Returns the early-pivot emoji for the active side and candidate state.
Parameters:
isHigh (bool): True for a high-side early label, false for a low-side early label
isCurrentCandidateBar (bool): True when the candidate bar is the current bar
Returns:
Early-pivot emoji
➖Live Stack Text Helpers➖
These helpers build the reusable text layer behind live stack labels. They handle padded line construction, signed delta wording, movement glyphs, and the multi-line center block used to display price, anchor tag, RSI, RSI delta, SMA, and SMA delta.
stackSignedRoundText(x)
Returns a rounded signed text value for live-stack display.
Parameters:
x (float): Value to round
Returns:
Signed rounded text
stackMoveGlyph(delta)
Returns the move glyph used by live-stack delta text.
Parameters:
delta (float): Delta value
Returns:
Move glyph
stackDeltaText(change, structTag, isPercent, pad)
Builds padded delta text for the live stack.
Parameters:
change (float): Delta value
structTag (string): Structure tag to append
isPercent (bool): Whether the delta should be formatted as a percent
pad (int): EM-space padding count
Returns:
Padded delta text
stackRsiDiffText(delta, structTag, pad)
Builds padded RSI-delta text for the live stack.
Parameters:
delta (float): RSI delta value
structTag (string): Structure tag to append
pad (int): EM-space padding count
Returns:
Padded RSI-delta text
stackCenterText(price, rsiVal, rsiDelta, rsiSma, rsiSmaDelta, anchorTag, pad, sigFigs)
Builds the live-stack center block text.
Parameters:
price (float): Current price
rsiVal (float): Current RSI value
rsiDelta (float): Current bar-to-bar RSI delta
rsiSma (float): Current RSI SMA value
rsiSmaDelta (float): Current bar-to-bar RSI SMA delta
anchorTag (string): Active anchor tag such as "➜H" or "➜L"
pad (int): EM-space padding count
sigFigs (simple int): Significant figures used for price formatting
Returns:
Center live-stack text block
➖Live Stack Label Object Helpers➖
These helpers manage the lifecycle of live center-style stack labels so scripts can create, update, or delete the visible stack objects without repeatedly rewriting that object-management logic.
manageCenterLabel(lblPrev, show, yVal, txt, textColor, xPos, linesBefore, linesAfter, sizeIn)
Creates, updates, or deletes a center-style live-stack label.
Parameters:
lblPrev (label): Existing label reference
show (bool): Whether the label should exist
yVal (float): Label y position
txt (string): Label text
textColor (color): Label text color
xPos (int): Label x position
linesBefore (int): Blank lines inserted before the text block
linesAfter (int): Blank lines inserted after the text block
sizeIn (simple string): Label size string
Returns:
Updated label reference
Local Pivot label demo (with pin emoji)— shows the library’s smaller same-side pivot label format on its own for a cleaner view of the local-label workflow.

It centralizes the parts of the workflow that tend to get rewritten across label-heavy scripts: label-size resolution, compact percent and price formatting, one-shot pivot label plotting, live directional label management, confirmed/local/current-RSI text builders, early-label emoji output, and live-stack text / object helpers.
On the example chart, the visible label workflows are materially driven by the library, whether through the confirmed pivot label text, the local pivot label text, the current RSI + SMA above-bar label, the early directional labels, or the live stack text and label-object lifecycle helpers used to keep those outputs updated cleanly on the chart.
How to use
Import the library near the top of your script in global scope, alongside any other imports, before you start calling its helpers.
Typical placement:
// version=6
indicator(...) or strategy(...)
import MYNAMEISBRANDON/PivotLabelsOutput_Utilities/1 as PLutils
This library does not confirm pivots, resolve structure tags, or choose label colors for you. Instead, it expects your script to already know the values it wants to display, then uses those resolved inputs to build the output layer.
For more information on libraries and incorporating them into your scripts, see the Libraries section of the Pine Script User Manual.
➖Label Size Helpers➖
These helpers convert simple UI-facing size strings into Pine label-size enums so scripts can keep one consistent size resolver across confirmed pivot labels, local pivot labels, current RSI labels, early labels, and live stack labels.
labelSizeFromString(sizeIn)
Resolves a Pine label size from a string input.
Parameters:
sizeIn (simple string): Size string. Expected values: "Tiny", "Small", "Normal", "Large", or "Huge"
Returns:
Pine label size enum
➖Numeric Formatting Helpers➖
These helpers handle compact numeric formatting for label-driven scripts. They let a script calculate percent change safely, format that change in a label-friendly way, and convert larger price values into compact significant-figure style text.
labelPercentChange(curr, prev)
Returns percent change from prev to curr.
Parameters:
curr (float): Current value
prev (float): Previous reference value
Returns:
Percent change or na when invalid
labelFormatPercent(p)
Formats a percent value for compact label output.
Parameters:
p (float): Percent value
Returns:
Formatted percent string
labelFormatCompactNumber(x, sig)
Formats a number using significant-figure style suffix output.
Parameters:
x (float): Value to format
sig (simple int): Significant figures to preserve
Returns:
Compact number string
➖Static Label Plot Helpers➖
These helpers create one-shot label outputs for scripts that want to place confirmed or local pivot labels on historical pivot bars, or simple above-bar informational labels, without managing a live label object afterward.
plotPivotLabel(x, y, txt, textColor, isHigh, sizeIn)
Creates a pivot label on a specific bar.
Parameters:
x (int): Label x position
y (float): Label y position
txt (string): Label text
textColor (color): Label text color
isHigh (bool): True for a high-side label, false for a low-side label
sizeIn (simple string): Label size string
Returns:
Created label reference
plotAboveBarLabel(x, y, txt, textColor, sizeIn)
Creates an above-bar informational label.
Parameters:
x (int): Label x position
y (float): Label y position
txt (string): Label text
textColor (color): Label text color
sizeIn (simple string): Label size string
Returns:
Created label reference
➖Directional Label Object Helpers➖
These helpers manage the lifecycle of live high-side and low-side label objects so scripts can create, update, or delete directional labels without repeating the same object-management logic each time.
manageDirectionalLabel(lbl, show, x, y, txt, textColor, isHigh, sizeIn)
Creates, updates, or deletes a directional label object.
Parameters:
lbl (label): Existing label reference
show (bool): Whether the label should exist
x (int): Label x position
y (float): Label y position
txt (string): Label text
textColor (color): Label text color
isHigh (bool): True for a high-side label, false for a low-side label
sizeIn (simple string): Label size string
Returns:
Updated label reference
➖Pivot Text Helpers➖
These helpers build the final text used by confirmed pivot labels, local pivot labels, confirmed pivot alerts, and the current RSI / SMA above-bar label. In other words, this region keeps the script’s visible wording consistent while leaving structure resolution and color decisions to the calling script.
buildMajorPivotLabelText(mode, priceText, priceStruct, rsiText, oscStruct, percentText, pivotLen, showLen)
Builds confirmed pivot label text.
Parameters:
mode (simple string): Label mode. Expected values: "Full" or "RSI Only"
priceText (string): Formatted pivot price
priceStruct (string): Price-side structure tag
rsiText (string): Formatted pivot RSI
oscStruct (string): RSI-side structure tag
percentText (string): Formatted percent-change text
pivotLen (int): Pivot length value
showLen (bool): Whether pivot length should be shown
Returns:
Confirmed pivot label text
buildLocalPivotLabelText(priceText, priceStruct, rsiText, rsiStruct, pivotLen, showPrice, showLen)
Builds local pivot label text.
Parameters:
priceText (string): Formatted local pivot price
priceStruct (string): Price-side structure tag
rsiText (string): Formatted local pivot RSI
rsiStruct (string): RSI-side structure tag
pivotLen (int): Pivot length value
showPrice (bool): Whether the price line should be shown
showLen (bool): Whether pivot length should be shown
Returns:
Local pivot label text
buildPivotAlertText(isHigh, priceText, pctText, rsiText, structTag, rsiValue, rsiOB, rsiOS)
Builds confirmed pivot alert text.
Parameters:
isHigh (bool): True for a high pivot, false for a low pivot
priceText (string): Formatted pivot price
pctText (string): Formatted percent-change text
rsiText (string): Formatted pivot RSI
structTag (string): RSI-side structure tag
rsiValue (float): Raw RSI value at the pivot
rsiOB (int): Overbought level
rsiOS (int): Oversold level
Returns:
Alert message text
buildCurrentRsiAboveBarText(currRsiText, structTag, smaText)
Builds current RSI / SMA above-bar label text.
Parameters:
currRsiText (string): Formatted current RSI text
structTag (string): Current live structure tag
smaText (string): Formatted SMA text
Returns:
Current RSI above-bar label text
➖Early Pivot Label Helpers➖
These helpers provide the reusable output primitive used by early pivot labels. This region intentionally stops at emoji selection so scripts with different structure-tag models and color logic can still reuse the same active-vs-carried-forward label cue.
earlyPivotEmoji(isHigh, isCurrentCandidateBar)
Returns the early-pivot emoji for the active side and candidate state.
Parameters:
isHigh (bool): True for a high-side early label, false for a low-side early label
isCurrentCandidateBar (bool): True when the candidate bar is the current bar
Returns:
Early-pivot emoji
➖Live Stack Text Helpers➖
These helpers build the reusable text layer behind live stack labels. They handle padded line construction, signed delta wording, movement glyphs, and the multi-line center block used to display price, anchor tag, RSI, RSI delta, SMA, and SMA delta.
stackSignedRoundText(x)
Returns a rounded signed text value for live-stack display.
Parameters:
x (float): Value to round
Returns:
Signed rounded text
stackMoveGlyph(delta)
Returns the move glyph used by live-stack delta text.
Parameters:
delta (float): Delta value
Returns:
Move glyph
stackDeltaText(change, structTag, isPercent, pad)
Builds padded delta text for the live stack.
Parameters:
change (float): Delta value
structTag (string): Structure tag to append
isPercent (bool): Whether the delta should be formatted as a percent
pad (int): EM-space padding count
Returns:
Padded delta text
stackRsiDiffText(delta, structTag, pad)
Builds padded RSI-delta text for the live stack.
Parameters:
delta (float): RSI delta value
structTag (string): Structure tag to append
pad (int): EM-space padding count
Returns:
Padded RSI-delta text
stackCenterText(price, rsiVal, rsiDelta, rsiSma, rsiSmaDelta, anchorTag, pad, sigFigs)
Builds the live-stack center block text.
Parameters:
price (float): Current price
rsiVal (float): Current RSI value
rsiDelta (float): Current bar-to-bar RSI delta
rsiSma (float): Current RSI SMA value
rsiSmaDelta (float): Current bar-to-bar RSI SMA delta
anchorTag (string): Active anchor tag such as "➜H" or "➜L"
pad (int): EM-space padding count
sigFigs (simple int): Significant figures used for price formatting
Returns:
Center live-stack text block
➖Live Stack Label Object Helpers➖
These helpers manage the lifecycle of live center-style stack labels so scripts can create, update, or delete the visible stack objects without repeatedly rewriting that object-management logic.
manageCenterLabel(lblPrev, show, yVal, txt, textColor, xPos, linesBefore, linesAfter, sizeIn)
Creates, updates, or deletes a center-style live-stack label.
Parameters:
lblPrev (label): Existing label reference
show (bool): Whether the label should exist
yVal (float): Label y position
txt (string): Label text
textColor (color): Label text color
xPos (int): Label x position
linesBefore (int): Blank lines inserted before the text block
linesAfter (int): Blank lines inserted after the text block
sizeIn (simple string): Label size string
Returns:
Updated label reference
Local Pivot label demo (with pin emoji)— shows the library’s smaller same-side pivot label format on its own for a cleaner view of the local-label workflow.
Notas de Lançamento
v2Pivot_Labels_Output_Utilities is a shared pivot label-output helper library for Pine scripts that already have their own pivot-confirmation, structure-tag, and color-resolution logic.
It centralizes the parts of the workflow that tend to get rewritten across label-heavy scripts: label-size resolution, compact percent and price formatting, one-shot pivot label plotting, live directional label management, confirmed/local/current-RSI text builders, early-label emoji output, local pivot record/reflow helpers, and live-stack text / object helpers.
This library is designed to stay focused on output and object management. It does not detect pivots, choose HH / LH / HL / LL structure tags, resolve divergence logic, or decide final colors. Calling scripts remain responsible for their own pivot engine, structure model, comparison rules, and visual interpretation.
Update: Local Pivot Reflow Record Helpers
This update adds a new Local Pivot Reflow Record Helpers section for scripts that need to store local pivot labels first, then reflow or render them later in visual pivot-index order.
This is especially useful for oscillator-based pivot workflows, where local pivots can confirm after the fact and sometimes arrive out of the same visual order seen on the chart. Instead of permanently scoring a local label the moment it confirms, a script can now store the local pivot as a record, keep those records sorted by pivot index, prune older records, remove records that collide with confirmed major pivots, and manage the label object attached to each stored record.
The new helpers are intentionally mechanical. They do not detect pivots, assign HH / LH / HL / LL structure, or choose final label colors. Calling scripts still provide the pivot engine, structure model, comparison logic, and color rules. The library simply provides the reusable storage and label-management layer so those scripts do not have to rebuild the same local-label record workflow each time.
New helper group:
➖Local Pivot Reflow Record Helpers➖
localPivotIsIdxNearAny(idxArr, idx, gap)
Checks whether a candidate pivot index is within a selected bar gap of any stored index.
localPivotPruneOldStoredIdxs(idxArr, minIdxToKeep)
Removes old stored indexes outside the active tracking window.
localPivotDeleteRecordAt(lblArr, idxArr, priceArr, oscArr, lenArr, i)
Deletes one stored local pivot record and its attached label object.
localPivotPruneRecords(lblArr, idxArr, priceArr, oscArr, lenArr, minIdxToKeep)
Prunes local pivot records older than the selected tracking window.
localPivotDeleteRecordsNear(lblArr, idxArr, priceArr, oscArr, lenArr, pivotIdx, gap)
Deletes local pivot records that are too close to a confirmed major pivot.
localPivotUpsertRecord(lblArr, idxArr, priceArr, oscArr, lenArr, idx, price, oscVal, pivotLen, maxRecords)
Inserts or updates a local pivot record while keeping records sorted left-to-right by pivot index.
localPivotNearestMajorRefToLeft(idxArr, priceArr, oscArr, idx)
Finds the nearest same-side major pivot reference to the left of a local pivot.
localPivotManageRecordLabel(lbl, show, isHigh, idx, price, txt, textColor, labelSize)
Creates, updates, or deletes the label object attached to one stored local pivot record.
Biblioteca do Pine
Em verdadeiro espírito TradingView, o autor publicou este código Pine como uma biblioteca de código aberto para que outros programadores Pine da nossa comunidade possam reutilizá-lo. Parabéns ao autor! Você pode usar esta biblioteca de forma privada ou em outras publicações de código aberto, mas a reutilização deste código em publicações é regida pelas Regras da Casa.
🆓 Free scripts:
⚡ Pro scripts: tradingview.com/script/hESCvPuH-Predictive-Volume-MTF-Pro/
🙋♂️ Get help with Pinescript: simplecrypto.life/get-help-with-pinescript
⚡ Pro scripts: tradingview.com/script/hESCvPuH-Predictive-Volume-MTF-Pro/
🙋♂️ Get help with Pinescript: simplecrypto.life/get-help-with-pinescript
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Biblioteca do Pine
Em verdadeiro espírito TradingView, o autor publicou este código Pine como uma biblioteca de código aberto para que outros programadores Pine da nossa comunidade possam reutilizá-lo. Parabéns ao autor! Você pode usar esta biblioteca de forma privada ou em outras publicações de código aberto, mas a reutilização deste código em publicações é regida pelas Regras da Casa.
🆓 Free scripts:
⚡ Pro scripts: tradingview.com/script/hESCvPuH-Predictive-Volume-MTF-Pro/
🙋♂️ Get help with Pinescript: simplecrypto.life/get-help-with-pinescript
⚡ Pro scripts: tradingview.com/script/hESCvPuH-Predictive-Volume-MTF-Pro/
🙋♂️ Get help with Pinescript: simplecrypto.life/get-help-with-pinescript
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.