Indicator · Pine Script v4 · Own pane

Pinescript - Plotting overlay=false

by RobACurtis· code credited to Gammapips

This educational script demonstrates basic plotting syntax and the overlay parameter in Pine Script v4.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code346
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago20 Jan 2024

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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

346 lines of Pine Script v4 from course_examples/plotting.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

plotting.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Gammapips


//@version=4
//   ____    _           _     _     _                 
//  |  _ \  | |   ___   | |_  | |_  (_)  _ __     __ _ 
//  | |_) | | |  / _ \  | __| | __| | | | '_ \   / _` |
//  |  __/  | | | (_) | | |_  | |_  | | | | | | | (_| |
//  |_|     |_|  \___/   \__|  \__| |_| |_| |_|  \__, |
//                                               |___/


//  ----------- ----------- OVERLAY ----------- -----------
// How do you want your plots to be displayed?

// **************************
study("Pinescript - Plotting overlay=false", overlay=false)
// Plots display separated from chart
// Good for separating plots from chart data
// No scaling issues
// **************************

// **************************
// study("Pinescript - Plotting overlay=true", overlay=true)
// Plots display on chart
// Good for visualizing plots with chart data
// Should be same scale as chart data
// **************************

// Note: If you wish to switch overlay, you will need to click “add to chart” again. 
// Simply changing the boolean and saving will not produce the result you desire.



//  ----------- ----------- PLOT FUNCTION ----------- -----------
// Plots a series of data onto the chart.

// **************************
plot(close)  // Basic plot function
// **************************
// Every study requires at least one plot annotation* (Unless you use some other output like bgcolor or barcolor)
// Plot annotations have 13 parameters, but only one is required -- the series type to plot!
// If it’s not a series type, Pine Script will  automatically cast the type into a series (in most cases, booleans won’t work)
// Up to 64 plot annotations can be on one script (This is a cumulation of all output series)
// Don’t worry about counting your plots though, Pine Script will let you know if you go over.

// Plot with ALL the arguments.
// **************************
// plot(close, 
//      title="Plot close", 
//      color=color.red, 
//      linewidth=1, 
//      style=plot.style_line, 
//      trackprice=true, 
//      transp=100,
//      histbase=6000, 
//      offset=-10, 
//      join=true, 
//      editable=false, 
//      display=display.all)
// **************************



//  ----------- ----------- USER INPUTS ----------- -----------
// These are variables you can change after compiling your code. 
// User can see and edit inputs. Inputs look and behave exactly the same as inputs of built-in Technical Analysis indicators.

// Possible values are input.bool, input.integer, input.float, input.string, input.symbol, input.resolution, input.session, input.source.
// Result of input function always should be assigned to a variable.

// **************************
// input_bool       = input(defval=false, title="On/Off", type=input.bool, confirm=true)
// input_integer    = input(defval=1, title="Pick a number 1-1000?", type=input.integer, minval=1, maxval=1000, confirm=true, step=10)
// input_float      = input(defval=1.0, title="", type=input.float)
// input_string     = input(defval='247', title="input string", type=input.string)
// input_symbol     = input(title="Symbol", type=input.symbol, defval="BTCUSD")
// input_resolution = input(title="Resolution", type=input.resolution, defval="60")
// input_session    = input(title="Session", defval="24x7",type=input.session, options=["24x7", "0900-1300", "1300-1700", "1700-2100"])
// input_source     = input(defval=close, title="OHLChl2", type=input.source)
// **************************



//  ----------- ----------- PLOTTING PRICE LEVELS ----------- -----------
// We can draw horizonatal lines at specific price levels on our charts by using hline()

// **************************
// hline(6000)  // Draws a horizontal line across the chart on the 6000 y-axis.
// hline(6000, title='6000 hline', color=color.gray, linestyle=hline.style_solid, linewidth=3, editable=true)
// **************************
// We can also assign hline functions to identifiers to be used in fill.
// **************************
// hline_10k = hline(10000)
// hline_5k  = hline(5000)
// **************************



//  ----------- ----------- COLORING BACKGROUNDS ----------- -----------
// There is two ways to color the backgrounds with Pine Script. fill() and bgcolor()

// Using fill() we can *fill* the background between two plots or two hlines.
// **************************
// fill(hline_10k, hline_5k)

// fill(hline(10000), hline(5000), color=color.red, transp=50, title='5-10k fill', editable=true)
// **************************
// We can do the same thing with plots!
// **************************
// plot_h    = plot(high)
// plot_l    = plot(low)
// fill(plot_h, plot_l, color=color.orange, transp=20, title="plot fill", editable=false, show_last=50)
// **************************

//  Fills background of bars with specified color using bgcolor() aka *background*color
// **************************
// bgcolor(color=color.blue)
// bgcolor(color=color.red, transp=20, offset=-1, editable=true, show_last=10, title="Last ten bgcolor")
// bgcolor(color=color.red, transp=20, offset=-2, editable=true, show_last=1, title="Last ten bgcolor")
// **************************



//  ----------- ----------- COLORING CANDLES ----------- -----------
// Sets the color of the bars. Order does not matter. Will always overlay=true even if overlay=false.

// **************************
// barcolor(color=color.red)
// barcolor(color=color.yellow, offset=0, editable=true, show_last=100, title="last 100 candles are blue")
// **************************



//  ----------- ----------- PLOTTING ARROWS ----------- -----------
// Plots up and down arrows on the chart. 
// Up arrow is drawn at every indicator positive value, down arrow is drawn at every negative value. 
// If indicator returns na then no arrow is drawn. 
// Arrows has different height, the more absolute indicator value the longer arrow is drawn.
// Use plotarrow function in conjunction with 'overlay=true' study parameter!
// Useful for showing strength of an indicator or direction + velocity (vector) of buy/sell.

// **************************
// plotarrow(close-open)
// plotarrow(close-open, offset=-2, title='offset', colorup=color.green, colordown=color.white, minheight=1, maxheight=200)
// **************************



//  ----------- ----------- PLOTTING SHAPES ----------- -----------
// Plots a shape on the chart. Using a series.

// POSSIBLE SHAPE STYLES: 
// shape.xcross, shape.cross, shape.triangleup, shape.triangledown, shape.flag, shape.circle, 
// shape.arrowup, shape.arrowdown, shape.labelup, shape.labeldown, shape.square, shape.diamond.

// POSSIBLE SHAPE LOCATIONS:
// location.abovebar, location.belowbar, location.top, location.bottom, location.absolute.

// POSSIBLE SHAPE SIZES:
// size.auto, size.tiny, size.small, size.normal, size.large, size.huge

// **************************
// study("Pinescript - Plotting overlay=false", overlay=true)
// series_bool = close > open
// plotshape(series_bool)  // The simplest way only requires only a series
// plot()
// offset_input = input(defval=-1, type=input.integer)
// plotshape(close, title="shapes", style=shape.diamond, location=location.absolute, color=color.blue, transp=20, offset=offset_input, text='diamond!', textcolor=color.red, size=size.small)
// **************************



//  ----------- ----------- PLOTTING CHARACTERS ----------- -----------
// Plots visual shapes using any given one Unicode character on the chart.
// Use plotchar function in conjunction with 'overlay=true' study parameter!
// https://unicode-table.com/en/

// **************************
// 😁 
// study("Pinescript - Plotting overlay=false", overlay=true)
// series_bool = close > open
// plotchar(series_bool)  // Just a series is the only required argument.
// plotchar(close) // series[float] will be cast into series[bool], unless location=location.absolute.
// plotchar(close, location=location.absolute)  // Plots a star on everycandle close price. instead of default above bar.
// plotchar(close < open, title='finger down', char='333', color=color.green, location=location.abovebar)
// plotchar(close > open, char='🙌', location=location.belowbar)
// plotchar(barstate.islast ? close[1] + close*.10: na, char='🧠', location=location.absolute, offset=10, size=size.large, text='use your')
// **************************

// Note: plotshape() and plotchar() are practically identical in function and form. Choose whichever one you would like based on your needs.



//  ----------- ----------- PLOTTING CUSTOM BARS & CANDLES ----------- -----------
// Plot your own candles with plotcandle. 
// This can be used as overlay=true or false. 
// Decent workaround for viewing multiple charts on a split screen without pro-version.

// **************************
// plotcandle(open=open, high=high, low=low, close=close)   // This is the simplest method. Will just plot the same candles, but in the default blue color.
// **************************


// A more complex example that plots candles from the weekly chart. Use on a lower timeframe.
// **************************
// ohlc() => [open, high, low, close]
// [o,h,l,c] = security(syminfo.tickerid, resolution='1W', expression=ohlc())  // Special function that gets the weekly candle
// plotcandle(open=o, high=h, low=l, close=c, color=color.yellow)  // Show last weeks candle and this weeks
// **************************

// Another example for those who wish to view different charts on the same screen without upgrading.
// **************************
// study("Pinescript - Adding a chart without Pro plan 🤫", overlay=false)  // Be sure to comment out any other study() before trying to use this one.
// ticker_id = input(defval="xrpusd", type=input.symbol, confirm=true)
// ohlc() => [open, high, low, close]
// [o,h,l,c] = security(ticker_id, resolution=timeframe.period, expression=ohlc())  // Special function that gets the weekly candle
// candle_color = c >= o ? color.green : color.red
// plotcandle(o,h,l,c, color=candle_color, wickcolor=color.gray)
// **************************

// Plot bar does the same thing as plotcandle. The only difference being it is a bar chart, without wicks and body.
// **************************
// plotbar(open,low, high, close)  // minimum required arguments.
// **************************



//  ----------- ----------- PLOTTING EXAMPLES ----------- -----------

// Plot vwap as a candle.
// **************************
// study("Vwap Candlesticks", overlay=true)
// v_open = vwap(open)
// v_high = vwap(high)
// v_low = vwap(low)
// v_close = vwap(close)
// color_vwap_candles = v_close > v_open ? color.green : color.red
// plotcandle(open=v_open, high=v_high, low=v_low, close=v_close, color=color_vwap_candles)
// plot(vwap)
// **************************







// plot rsi as a candle!
// **************************
// study("RSI Candlesticks", overlay=false)
// rsi_open = rsi(open, 14)
// rsi_high = rsi(high, 14)
// rsi_low = rsi(low, 14)
// rsi_close = rsi(close, 14)
// color_rsi_candles= rsi_close > rsi_open ? color.green : color.red
// plotcandle(open=rsi_open, high=rsi_high, low=rsi_low, close=rsi_close, color=color_rsi_candles)
// hline(70)
// hline(30)
// plot(rsi(close, 14))
// // **************************


// Build your own custom rsi indicator
// **************************
// study("Custom RSI of VWAP", overlay=false)
// length      = input(title="Rsi Length",  type=input.integer, defval=14, minval=1)  // User input for rsi length
// upper_bound = input(title="Upper Bound", type=input.integer, defval=70, minval=0, maxval=100)  // User input for overbought horizontal line
// lower_bound = input(title="Lower Bound", type=input.integer, defval=30, minval=0, maxval=100)  // User input for oversold horizontal line

// vwap_rsi     = rsi(vwap, length)   // Calculation of rsi with volume weighted average price as source, and user input as length
// rsi_is_above = vwap_rsi >= upper_bound   // If the value of vwap_rsi is above the upperbound, this becomes true. Else false.
// rsi_is_below = vwap_rsi <= lower_bound   // This is the same but for the lowerbound.


// plot(vwap_rsi)  // Plot the rsi
// upper_hl = hline(upper_bound)   // Plot the hlines and assign to be used for fill
// lower_hl = hline(lower_bound)
// fill(upper_hl, lower_hl, color=color.purple)   // Fills the area between hlines. Default color is blue.
// **************************

// Plotting additional shapes for more intuitive rsi.

// This won't work with overlay=false,
// **************************
// plotshape(rsi_is_above, style=shape.arrowdown, location=location.abovebar, color=color.red, text="Rsi is overbought!", textcolor=color.red)
// plotshape(rsi_is_below, style=shape.arrowup, location=location.belowbar, color=color.green, text="Rsi is oversold!", textcolor=color.green)
// **************************

//Lets do the same thing, but change the location argument. Also, I will remove the text.
// **************************
// plotshape(rsi_is_above, style=shape.arrowdown, location=location.top, color=color.red)
// plotshape(rsi_is_below, style=shape.arrowup, location=location.bottom, color=color.green)
// **************************

// The text would be nice, just in case someone using this indicator is colorblind or maybe they don't understand arrows becuause they are an alien.
// **************************
// input_sell_sym = input(defval='🐻', confirm=true, title="Select Bearish Symbol", type=input.string, options=['⚠','', '🐻', '📉', '❎'])
// input_buy_sym = input(defval="🐮", confirm=true, title="Select Bullish Symbol", type=input.string, options=['⚠','', "🐮", '📈', '✅'])
// plotchar(rsi_is_above, location=location.top, char=input_sell_sym)
// plotchar(rsi_is_below, location=location.bottom, char=input_buy_sym)
// **************************

//  unless we use location.absolute
// **************************
// plotshape(rsi_is_above?vwap_rsi: na, style=shape.arrowdown, location=location.absolute, color=color.red, text="Rsi is overbought!", textcolor=color.red)
// plotshape(rsi_is_below?vwap_rsi: na, style=shape.arrowup, location=location.absolute, color=color.green, text="Rsi is oversold!", textcolor=color.green)
// **************************

// Or we could just use bgcolor
// **************************
// bgcolor(rsi_is_above ? color.red : rsi_is_below ? color.green : na)
// **************************

// We could even color the bars on the main chart.
// **************************
// barcolor(rsi_is_above ? color.red : rsi_is_below ? color.green : color.white)
// **************************


///// Project 1
//@version=4
study("My Script", overlay=true)

// RSI
rsi = rsi(close, 14)
// MACD
[macdLine, signalLine, histLine] = macd(close, 12, 26, 9)
// BB
[middle, upper, lower] = bb(close, 5, 4)


// PLOTS
// rsi plot
plot(rsi, title='rsi', color=color.purple)

//macd plot
plot(histLine, title="Histogram", style=plot.style_columns)
plot(macdLine, title="MACD", transp=0)
plot(signalLine, title="Signal", transp=0)

// bb plot
plot(middle, color=color.yellow)
plot(upper, color=color.red)
plot(lower, color=color.green)

Overview

Pinescript - Plotting overlay=false calculates and plots the closing price in a separate pane below the price chart using the default plot function. The source code serves as an instructional guide, containing commented reference examples that explain study overlay behaviors, all thirteen plot function arguments, and various user input data types. It does not provide any trading signals or execution logic.

Details

Published by

RobACurtis on GitHub

Code credit

Gammapips, as written in the script's header

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

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

pinescripttradingtradingview

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

Asymmetrical RSI

by everget
948 stars

Asymmetrical RSI is an indicator that computes a custom relative strength index from the rate of change of a user-selected source. It plots the resulting ARSI line in a separate pane with color coding that turns green above the overbought level and red below t

Indicator v4 Oscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Asymmetrical RSI

This indicator calculates momentum setups based on the Relative Strength Index (RSI) and plots in a separate pane. It offers multiple scanning modes such as Continuous Break, Continuous Retracement, Flip Break, Flip Retracement, and both regular and hidden div

Indicator v6 Oscillators & momentumDivergence Repaints
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Indicator
549 stars

Range Volume Change compares volume inside a chosen session window with the same window on the previous day and plots that change as a percentage. It accumulates volume during the window and, when enabled, volume outside it, drawing growing columns in a separa

Indicator v5 VolumeSessions & time Repaints
Updated 10 months ago · None stated GitHub repository of Range Volume Change

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

Mojito v3 Strategy

by namuan
318 stars

The Mojito v3 Strategy indicator evaluates volatility term structure by calculating the ratio between front-month and second-month VIX futures contracts. It smooths this ratio using a configurable median filter and compares the result against user-defined uppe

Indicator v5 Volatility & bands
Updated 2 months ago · MIT GitHub repository of Mojito v3 Strategy

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers