Indicator · Pine Script v5 · On the chart

Chart Viewer

by hsmalvajerdi

Chart Viewer overlays user-supplied price data on the chart.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code73
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago17 Apr 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

73 lines of Pine Script v5 from script.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

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

//@version=5
indicator("Chart Viewer", overlay = true)

// ===================================================== Definitions =====================================================
type Candle
    float _open = na
    float _high = na
    float _low = na
    float _close = na

type Order
    int left = na
    int right = na
    float green_value = na
    float middle_value = na
    float red_value = na
// ======================================================================================================================

// ===================================================== Your Array =====================================================
var Candle[] candles = array.from(Candle.new(2.0, 4.0, 1.0, 3.0), Candle.new(3.0, 5.0, 2.0, 4.0))
var Order[] orders = array.from(Order.new(1, 4, 5.4, 1.5, 1), Order.new(6, 8, 1, 2.5, 3))
// ======================================================================================================================

// ==================================================== Plot Candles ====================================================
var candles_length = candles.size()

candle = Candle.new()
candle_color = color.gray
if bar_index < candles_length
    candle := candles.get(bar_index)

_open = candle._open
_high = candle._high
_low = candle._low
_close = candle._close

is_green = _open < _close
is_gray = _open == _close
is_red = not (is_green or is_gray)
candle_color := is_green ? color.green : (is_gray ? color.gray : color.red)

plotcandle(open = _open, high = _high, low = _low, close = _close, title = "Chart", color = candle_color, bordercolor = candle_color, wickcolor = candle_color)
// ======================================================================================================================

// ==================================================== Plot Orders =====================================================
type OrderElement
    box g_box = na
    box r_box = na
    line g_line = na
    line m_line = na
    line r_line = na

drawOrder(Order _order) =>
    left = _order.left
    right = _order.right
    green_value = _order.green_value
    middle_value = _order.middle_value
    red_value = _order.red_value
    oe = OrderElement.new()
    oe.g_box := box.new(left, green_value, right, middle_value, xloc=xloc.bar_index, bgcolor = color.rgb(0, 228, 0, 81), border_color = color.rgb(0, 0, 0, 100))
    oe.r_box := box.new(left, middle_value, right, red_value, xloc=xloc.bar_index, bgcolor = color.rgb(228, 0, 0, 81), border_color = color.rgb(0, 0, 0, 100))
    oe.g_line := line.new(left, green_value, right, green_value, xloc=xloc.bar_index, color = color.white)
    oe.m_line := line.new(left, middle_value, right, middle_value, xloc=xloc.bar_index, color = color.white)
    oe.r_line := line.new(left, red_value, right, red_value, xloc=xloc.bar_index, color = color.white)
    oe

if barstate.isfirst
    for _order in orders
        drawOrder(_order)
// ======================================================================================================================

Overview

Chart Viewer reads a Candle array and plots each bar's open, high, low and close with plotcandle, coloring green when close is above open, gray when they match, and red otherwise. A second Order array draws green and red boxes plus white horizontal lines between bar indexes for three price levels. The script has no input settings; arrays are edited in the source. It draws on the price chart and does not generate trade signals or exits.

Details

Published by

hsmalvajerdi on GitHub

Draws

On the price 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.

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

947 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 12 days ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
575 stars

The indicator plots ICT displacement candles on the price chart and can switch to retracement scanning. Displacement requires a move larger than a set share of the 14-bar average high-low range, lasting at least a chosen number of bars, with optional close, pr

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Displacement Candles Indicator
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

1833 Tracker

by Allen1212
303 stars

1833 Tracker is an overlay indicator that visualizes historical buy and sell transactions executed by ARK Invest ETFs for the stock on the main price chart. It displays trade dates using green buy and red sell labels positioned relative to price bars, indicati

Indicator v4
Updated 2 years ago · None stated GitHub repository of 1833 Tracker

More indicators

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers