Library · Pine Script v6 · Library

Plot Lib

by InNoobWeTrust

This library supplies reusable drawing helpers rather than its own indicator output.

View on GitHub

GitHub stars4on the repository
Pine versionv6current
Lines of code87
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last updatetoday28 Oct 2026

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

87 lines of Pine Script v6 from .innoobwetrust/life_hacks/tradingview/lib/plot_lib.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

plot_lib.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// ©  InNoobWeTrust

//@version=6

// @description helper library for common plotting needs
library("plot_lib", overlay = false)

//===============================================================================
// Types
//===============================================================================

export type PositionPlot
    line tp
    line sl
    line c
    linefill tp_fill
    linefill sl_fill

export type TfBar
    float o
    float h
    float l
    float c
    int t_o
    int t_c

export type TfBarZone
    int period_seconds
    TfBar bar

export type TfBarZonePlot
    line h
    line l
    linefill f

//===============================================================================
// Functions
//===============================================================================

// @function Draw entry with TP/SL
// @param tp The take profit price
// @param sl The stop loss price
// @param bars The width of the drawing
// @returns The drawings ids
export plot_position_entry(float tp,float sl, int bars) =>
    tp_color = color.new(#40ee40,80)
    tp_fill_color = color.new(#40ee40,90)
    sl_color = color.new(#ee4040,80)
    sl_fill_color = color.new(#ee4040,90)
    tp_plt = line.new(bar_index,tp,bar_index + bars,tp,xloc = xloc.bar_index,color=tp_color,force_overlay = true)
    sl_plt = line.new(bar_index,sl,bar_index + bars,sl,xloc = xloc.bar_index,color=sl_color,force_overlay = true)
    close_plt = line.new(bar_index,close,bar_index+bars,close,xloc = xloc.bar_index,color = color(na),force_overlay = true)
    tp_fill = linefill.new(tp_plt,close_plt,tp_fill_color)
    sl_fill = linefill.new(sl_plt,close_plt,sl_fill_color)
    // Return the drawings
    PositionPlot.new(tp_plt,sl_plt,close_plt,tp_fill,sl_fill)

// @function Clear position plot
// @param pos_plt The plot to clear
export clear_position_plot(PositionPlot pos_plt) =>
    linefill.delete(pos_plt.tp_fill)
    linefill.delete(pos_plt.sl_fill)
    line.delete(pos_plt.c)
    line.delete(pos_plt.tp)
    line.delete(pos_plt.sl)

// @function Plot the price zone of TfBar
// @param z Zone data of TfBar
// @param clr Color for the zone
export plot_tf_zone(TfBarZone z, color clr, bool extend_right = false) =>
    bar_duration = time_close - time
    bars_back = int((time - z.bar.t_o) / bar_duration)
    left = time - bars_back * bar_duration
    right = time_close
    // Line for high value
    h = line.new(left, z.bar.h, right, z.bar.h, xloc = xloc.bar_time,extend = extend_right ? extend.right : extend.none, color = clr, style = line.style_solid, force_overlay = true)
    l = line.new(left, z.bar.l, right, z.bar.l, xloc = xloc.bar_time,extend = extend_right ? extend.right : extend.none, color = clr, style = line.style_solid, force_overlay = true)
    f = linefill.new(h,l,clr)
    TfBarZonePlot.new(h,l,f)

// @function Clear plotted TfBarZone
// @param z Plot data
export clear_tf_zone(TfBarZonePlot z) =>
    linefill.delete(z.f)
    line.delete(z.h)
    line.delete(z.l)

Overview

Plot Lib draws take-profit and stop-loss levels around an entry price, with translucent fills between those levels and the close, and it can remove those drawings. It also plots a timeframe bar's high and low as a filled zone, optionally extending the lines to the right, and provides a matching clear function. Callers pass prices, bar width, zone data, and color. Drawings are forced onto the price chart.

Details

Published by

InNoobWeTrust on GitHub

Type

Library, Pine Script v6

Draws

Library (no plots)

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.

Topics

dotfiles

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

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

KernelFunctions

by artificial-intelligence-edge
75 stars

KernelFunctions is a Pine Script v5 library that exports kernel weight functions for Nadaraya-Watson style estimation. It calculates a Rational Quadratic kernel, a Gaussian kernel based on a radial basis function, and a periodic kernel that models repeating be

Library v5
Updated 2 days ago · MIT GitHub repository of KernelFunctions

Ta

by nersent
29 stars

This Pine Script v5 library exports thin wrappers around built-in technical analysis functions. It covers moving averages, momentum measures such as RSI and CCI, volatility tools including ATR and standard deviation, range extremes, cross detection, and runnin

Library v5
Updated 11 months ago · Custom licence GitHub repository of Ta

Bands

by heyphat
26 stars

This library exports a Band type and functions that build a simple-moving-average basis with upper and lower envelopes from standard deviation. It classifies a source as above, below, or inside those envelopes, measures band width, and scales an imported z-sco

Library v6 Volatility & bandsMoving averages
Updated 2 months ago · AGPL-3.0 GitHub repository of Bands

Mylib

by ferranbt
21 stars

This script serves as a minimal utility library written in Pine Script v6. It provides an exported helper function that calculates the sum of two numeric arguments. As a reusable code library, it produces no visual plots, charts, or trading signals, and it con

Library v6
Updated 7 weeks ago · MPL-2.0 GitHub repository of Mylib

HLevel

by stupenkov
14 stars

HLevel is a Pine Script v5 utility library designed to manage horizontal price levels for cryptocurrency charts. It defines custom types for pivots and levels, along with methods to initialize, add, track, and expire price levels based on pivot high and pivot

Library v5
Updated 3 years ago · None stated GitHub repository of HLevel

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