PivotStructureOutline_UtilitiesThis library contains reusable pivot structure outline helpers for Pine scripts that already work with confirmed pivot highs and lows. It is designed to provide the reusable outline and anchor-box layer for scripts that already have their own pivot-confirmation logic, so those scripts can keep their structure visuals consistent without repeatedly rebuilding the same framework.
It brings together the parts of the workflow that are often rewritten in structure-based scripts: resolving pivot-close anchors, selecting wick vs close anchor behavior, building live outline geometry, building pivot structure anchor-box geometry, and managing the line and box objects that render those visuals.
Everything on the example chart is materially driven by the library, whether through the selected outline anchor source, the outline geometry itself, the midpoint-start logic, the pivot structure anchor boxes, or the shared line/box lifecycle helpers used to keep those visuals 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. This mirrors the import-first usage pattern shown on your recent library page.
Typical placement:
//@version=6
indicator(...) or strategy(...)
import MYNAMEISBRANDON/PivotStructureOutline_Utilities/1 as PSOutils
This library is engine-agnostic. It does not confirm pivots for you. Instead, it expects your script to already know its confirmed high/low pivot indexes and anchor values, then uses those resolved inputs to build the outline and anchor-box layer.
➖Outline Line Style Helpers➖
These helpers convert simple UI-facing style strings into Pine line style enums so scripts can keep one consistent style resolver across outline lines, midpoint lines, and connector lines.
outlineLineStyle(styleIn)
Resolves a Pine line style from a string input.
Parameters:
styleIn (simple string): Style string. Expected values: "Solid", "Dashed", or "Dotted"
Returns:
Pine line style enum
➖Pivot Structure Outline Helpers➖
These helpers build the actual pivot structure outline framework from already-confirmed high/low pivot anchors. They let a script resolve a pivot-close anchor, choose whether the outline should use wick or close anchors, and generate the live geometry needed for the top line, bottom line, midpoint, and left-side connectors.
outlinePivotCloseFromIdx(pivotIdx, closeValue)
Returns the close value belonging to a confirmed pivot index.
Parameters:
pivotIdx (int): Confirmed pivot bar_index
closeValue (float): Close series
Returns:
Confirmed pivot close value
outlineSelectedAnchors(anchorMode, highWickAnchor, lowWickAnchor, highCloseAnchor, lowCloseAnchor)
Selects the active outline anchors from Wick or Close mode.
Parameters:
anchorMode (simple string): Anchor mode. Expected values: "Wick" or "Close"
highWickAnchor (float): Confirmed high-side wick anchor
lowWickAnchor (float): Confirmed low-side wick anchor
highCloseAnchor (float): Confirmed high-side close anchor
lowCloseAnchor (float): Confirmed low-side close anchor
Returns:
Selected high anchor, selected low anchor, is outline-valid
outlineGeometry(highPivotIdx, lowPivotIdx, highAnchor, lowAnchor, connectorSourceMode, midlineStartMode, highValue, lowValue, closeValue)
Returns the live geometry for the pivot structure outline system.
Parameters:
highPivotIdx (int): Confirmed high pivot bar_index
lowPivotIdx (int): Confirmed low pivot bar_index
highAnchor (float): Selected top outline anchor
lowAnchor (float): Selected bottom outline anchor
connectorSourceMode (simple string): Connector source mode. Expected values: "Wick" or "Close"
midlineStartMode (simple string): Midline start mode. Expected values: "Most Recent Pivot" or "Left Outline"
highValue (float): High series
lowValue (float): Low series
closeValue (float): Close series
Returns:
ok, leftX, rightX, midX1, topY, bottomY, midY, leftTopConnectorY, leftBottomConnectorY
➖Pivot Structure Anchor Box Helpers➖
These helpers build directional top and bottom pivot structure anchor boxes from confirmed pivot bars. They let a script choose whether those boxes use wick-only extension from the candle body or the full candle body, then return the live coordinates needed to render those boxes forward to the current bar.
outlineAnchorBoxGeometry(highPivotIdx, lowPivotIdx, boxAreaMode, openValue, highValue, lowValue, closeValue)
Returns the live geometry for top and bottom pivot structure anchor boxes.
Parameters:
highPivotIdx (int): Confirmed high pivot bar_index
lowPivotIdx (int): Confirmed low pivot bar_index
boxAreaMode (simple string): Box area mode. Expected values: "Wick" or "Body"
openValue (float): Open series
highValue (float): High series
lowValue (float): Low series
closeValue (float): Close series
Returns:
showHighBox, showLowBox, highLeftX, lowLeftX, boxRightX, highTopY, highBottomY, lowTopY, lowBottomY
➖Line Object Helpers➖
These helpers manage the lifecycle of live line objects so scripts can create, update, or delete outline-related lines without rewriting that object-management logic each time.
outlineManageLine(enabled, ln, x1, y1, x2, y2, col, width, style)
Creates, updates, or deletes a line object.
Parameters:
enabled (bool): Whether the line should exist
ln (line): Existing line reference
x1 (int): Start x position
y1 (float): Start y position
x2 (int): End x position
y2 (float): End y position
col (color): Line color
width (int): Line width
style (string): Line style
Returns:
Updated line reference
➖Box Object Helpers➖
These helpers manage the lifecycle of live box objects so scripts can create, update, or delete pivot structure anchor boxes without repeating the same box-management code in every script.
outlineManageBox(enabled, bx, left, top, right, bottom, bgColor, borderColor, borderStyle, borderWidth)
Creates, updates, or deletes a box object.
Parameters:
enabled (bool): Whether the box should exist
bx (box): Existing box reference
left (int): Left x position
top (float): Top y position
right (int): Right x position
bottom (float): Bottom y position
bgColor (color): Box background color
borderColor (color): Box border color
borderStyle (string): Box border style
borderWidth (int): Box border width
Returns:
Updated box reference
Library

