Library · Pine Script v5 · Library

LabelHelper

by Electrified-Trading

This library provides utility functions for managing labels on a TradingView chart.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code111
Settings0inputs
LicenceMPL-2.0
Last update1 year ago7 Jul 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new library, select all of the template text and paste. Press Save and give it a name.
  4. 4Publish or import itA library draws nothing. Publish it from the editor, then import its functions in your own scripts.

Source Code

111 lines of Pine Script v5 from LabelHelper.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

LabelHelper.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Electrified (electrifiedtrading)

// @version=5
// @description Utility for managing active labels on the chart.
library('LabelHelper', true)
import Electrified/Time/1

//////////////////////////////////////////////////
// @function Refreshes the x position of label.
// @param lbl The label to update.
// @param offset A positive value will push label one bar to the right and a negative value to the left.
// @returns The time value that was used.
export refreshXPos(
  label lbl,
  int offset = 0) =>
    var barLength = Time.bar()
    t = time + offset * barLength
    label.set_x(lbl, t)
    t
//////////////////////////////////////////////////

//////////////////////////////////////////////////
// @function For creating a label at the last bar.
// @param level The value to display the label at.
// @param txt The text to show on the label.
// @param labelColor The background color of the label.
// @param textColor The text color of the label.
// @param size The size of the text. Default is large.
// @param textAlign The alignment of the text.  Default is left.
// @param offset A positive value will push label to the right and a negative to the left.
// @param tooltip The optional tooltip of the label.
// @returns The label that was created.
export create(
  float level,
  string txt,
  color labelColor = color.gray,
  color textColor = color.white,
  string size = size.large,
  string textAlign = text.align_left,
  int offset = 0,
  string tooltip = '') =>
    t = time + offset * Time.bar()
    label.new(t, level, txt, xloc.bar_time, yloc.price, labelColor, label.style_label_left, textColor, size, textAlign, tooltip)
//////////////////////////////////////////////////

//////////////////////////////////////////////////
// @function [DEPRECATED use .manage(…) instead] For displaying a label at the last bar.
// @param level The value to display the label at.
// @param txt The text to show on the label.
// @param labelColor The background color of the label.
// @param textColor The text color of the label.
// @param size The size of the text. Default is large.
// @param textAlign The alignment of the text.  Default is left.
// @param offset A positive value will push label to the right and a negative to the left.
// @param tooltip The optional tooltip of the label.
// @returns The label being managed.
export add(
  float level,
  string txt,
  color labelColor = color.gray,
  color textColor = color.white,
  string size = size.large,
  string textAlign = text.align_left,
  int offset = 0,
  string tooltip = '') =>
    // Create label on the first bar.
    lbl = create(level, txt, labelColor, textColor, size, textAlign, offset, tooltip)
    label.delete(lbl[1])
    lbl
//////////////////////////////////////////////////

//////////////////////////////////////////////////
// @function For displaying a label at the last bar.
// @param src The existing label to manage.
// @param txt The text to show on the label.
// @param labelColor The background color of the label.
// @param textColor The text color of the label.
// @param size The size of the text. Default is large.
// @param textAlign The alignment of the text.  Default is left.
// @param offset A positive value will push label to the right and a negative to the left.
// @param tooltip The optional tooltip of the label.
// @returns The active label (or 'na' if no text was provided).
export manage(
  series label src,
  float level,
  string txt,
  color labelColor = color.gray,
  color textColor = color.white,
  string size = size.large,
  string textAlign = text.align_left,
  int offset = 0,
  string tooltip = '') =>

    label result = na
    if not na(src) // possible difference during live session.
        label.delete(src)    
    if not na(src[0])
        label.delete(src[0])
    if not na(src[1])
        label.delete(src[1])

    if not na(txt) and txt != ""
        result := create(level, txt, labelColor, textColor, size, textAlign, offset, tooltip)

    result
//////////////////////////////////////////////////

// Demo
var label lbl = na
lbl := manage(lbl, close, "CLOSE", offset = 1, tooltip = "This is\nthe close.")

Overview

LabelHelper allows creating labels at the last bar with specified levels, text, colors, and sizes. The refreshXPos function updates the x position of existing labels with optional bar offsets. The manage function handles existing labels by updating their text. Labels are drawn on the price chart. It supports alignment and tooltips. This is useful for annotations, support/resistance levels, or other fixed price markings.

Details

Published by

Electrified-Trading on GitHub

Type

Library, Pine Script v5

Draws

Library (no plots)

Category

Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Mirpapa Lib Line

by alvinng214
2 stars

This library creates and tracks horizontal lines on the chart. It supports two breach modes: price and close. When a line is breached, it increments a break count up to a maximum value and can finalize the line with a close color. The data structure holds line

Library v6 Support & resistanceSMC / ICT / price action
Updated 2 months ago · None stated GitHub repository of Mirpapa Lib Line

SFA FlowLiquidity v1

by genesisgrubio39
1 stars

The SFA FlowLiquidity library computes structural flow and liquidity events from price data. It detects sweep ups and downs with associated scores, identifies liquidity levels, and applies session and regime filters. Persistent arrays track liquidity prices, b

Library v6 SMC / ICT / price actionSupport & resistance
Updated 10 months ago · None stated GitHub repository of SFA FlowLiquidity v1

PineDraw

by 345-strategies
5 stars

PineDraw is a Pine Script v6 library that provides object primitives for drawing and updating price levels on the chart. It enables indicators and strategies to maintain lines, boxes, and labels in place by updating existing objects instead of deleting and rec

Library v6 Support & resistance
Updated 2 days ago · MPL-2.0 GitHub repository of PineDraw

ZigZag

by rubystar0512
5 stars

This library calculates ZigZag pivots and draws connecting lines on the price chart. It changes direction when price moves beyond a percentage deviation after a set pivot depth, then stores each pivot with optional labels for reversal price, cumulative volume,

Library v5 Support & resistance
Updated 2 years ago · None stated GitHub repository of ZigZag

SMC Engine Private

by skipp-dev
1 stars

This Pine Script v6 library serves as an internal engine for Smart Money Concepts (SMC), providing types, tracking, and rendering logic for order blocks, fair value gaps, and market structure. It calculates order block parameters including quality scores, heig

Library v6 SMC / ICT / price actionSupport & resistance
Updated 2 days ago · None stated GitHub repository of SMC Engine Private
261 stars

AIActivationFunctionsBipolarSigmoid is a Pine Script library that provides mathematical implementations of the bipolar sigmoid activation function and its derivatives for machine learning algorithms. It calculates bipolar sigmoid values bounded between -1 and

Library v5 AI / machine learning
Updated 4 years ago · None stated GitHub repository of AIActivationFunctionsBipolarSigmoid

More libraries

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers