Indicator · Pine Script v5 · On the chart

Vector Candles

by benso87

Vector Candles is an overlay indicator that recolors price candles using PVSRA volume rules taken from the Traders Reality concept.

View on GitHub

GitHub stars24on the repository
Pine versionv5runs as is
Lines of code119
Settings0inputs
LicenceMPL-2.0
Last update4 years ago5 Oct 2022

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

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

Vector Candles.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Just the vector candle part of the Traders Reality indicator


//@version=5
indicator('Vector Candles', overlay=true, max_bars_back=300,max_boxes_count=500, max_lines_count=500, max_labels_count=500)


//Non repainting security
f_security(_symbol, _res, _src, _repaint) =>
    request.security(_symbol, _res, _src[_repaint ? 0 : barstate.isrealtime ? 1 : 0])[_repaint ? 0 : barstate.isrealtime ? 0 : 1]


// Basic vars (needed in functions)

// Only render intraday
validTimeFrame = timeframe.isintraday == true

// If above the 5 minute, we start drawing yesterday. below, we start today
levelsstart = timeframe.isseconds == true or timeframe.isminutes == true and timeframe.multiplier < 5 ? time('D') : time('D') - 86400 * 1000
//levelsstartbar = ta.barssince(levelsstart)


// Functions
// new_bar: check if we're on a new bar within the session in a given resolution
new_bar(res) =>
    ta.change(time(res)) != 0

// PVSRA
// From MT4 source:

//   Situation "Climax"
//   Bars with volume >= 200% of the average volume of the 10 previous chart TFs, and bars
//   where the product of candle spread x candle volume is >= the highest for the 10 previous
//   chart time TFs.
//   Default Colors:  Bull bars are green and bear bars are red.

//   Situation "Volume Rising Above Average"
//   Bars with volume >= 150% of the average volume of the 10 previous chart TFs.
//   Default Colors:  Bull bars are blue and bear are blue-violet.

// We want to be able to override where we get the volume data for the candles.


pvsra_security(sresolution, sseries) =>
    request.security(syminfo.tickerid, sresolution, sseries[barstate.isrealtime ? 1 : 0], barmerge.gaps_off, barmerge.lookahead_off)
pvsra_security_1 = pvsra_security('', volume)
pvsra_volume = volume
pvsra_security_2 = pvsra_security('', high)
pvsra_high = high
pvsra_security_3 = pvsra_security('', low)
pvsra_low = low
pvsra_security_4 = pvsra_security('', close)
pvsra_close = close
pvsra_security_5 = pvsra_security('', open)
pvsra_open = open

//label.new(overridesym ? 0 : na, low, text = "PVSRA Override: " + pvsra_sym, xloc = xloc.bar_index, yloc=yloc.belowbar,style=label.style_label_down, size=size.huge)

// The below math matches MT4 PVSRA indicator source
// average volume from last 10 candles
sum_1 = math.sum(pvsra_volume, 10)
sum_2 = math.sum(volume, 10)
av = sum_2 / 10
//climax volume on the previous candle
value2 = volume * (high - low)
// highest climax volume of the last 10 candles
hivalue2 = ta.highest(value2, 10)
// VA value determines the bar color. va = 0: normal. va = 1: climax.  va = 2: rising
iff_1 = pvsra_volume >= av * 1.5 ? 2 : 0
iff_2 = pvsra_volume >= av * 2 or value2 >= hivalue2 ? 1 : iff_1
iff_3 = volume >= av * 1.5 ? 2 : 0
iff_4 = volume >= av * 2 or value2 >= hivalue2 ? 1 : iff_3
va = iff_4

// Bullish or bearish coloring
isBull = close > open

CUColor = color.lime  // Climax up (bull) bull and bear both start with b so it would be weird hence up down
CDColor = color.red  // Climax down (bear)

AUColor = color.blue  //Avobe average up (bull)
ADColor = color.fuchsia  //Above average down (bear))

// Not used
//NUColor = #999999
//NDColor = #4d4d4d

// candleColor = iff(climax,iff(isBull,CUColor,CDColor),iff(aboveA,iff(isBull,AUColor,ADColor),iff(isBull,NUColor,NDColor)))
iff_5 = va == 2 ? AUColor : na
iff_6 = va == 1 ? CUColor : iff_5
iff_7 = va == 2 ? ADColor : na
iff_8 = va == 1 ? CDColor : iff_7
candleColor = isBull ? iff_6 : iff_8
barcolor(candleColor)

alertcondition(va > 0, title='Alert on Any Vector Candle', message='{{ticker}} Vector Candle on the {{interval}}')

alertcondition(candleColor == color.lime, title='Green Vector Candle', message='{{ticker}} Green Vector Candle on the {{interval}} Note: alert triggers in real time before the candle is closed unless you choose "once per bar close" option - ie the alert might trigger at some point and the pa after that could change the vector color completely. Use with caution.')
alertcondition(candleColor == color.red, title='Red Vector Candle', message='{{ticker}} Red Vector Candle on the {{interval}} Note: alert triggers in real time before the candle is closed unless you choose "once per bar close" option- ie the alert might trigger at some point and the pa after that could change the vector color completely. Use with caution.')
alertcondition(candleColor == color.blue, title='Blue Vector Candle', message='{{ticker}} Blue Vector Candle on the {{interval}} Note: alert triggers in real time before the candle is closed unless you choose "once per bar close" option- ie the alert might trigger at some point and the pa after that could change the vector color completely. Use with caution.')
alertcondition(candleColor == color.fuchsia, title='Purple Vector Candle', message='{{ticker}} Purple Vector Candle on the {{interval}} Note: alert triggers in real time before the candle is closed unless you choose "once per bar close" option- ie the alert might trigger at some point and the pa after that could change the vector color completely. Use with caution.')

redGreen = candleColor ==  color.lime and candleColor[1] == color.red
greenRed = candleColor ==  color.red and candleColor[1] == color.lime
redBlue = candleColor ==  color.blue and candleColor[1] == color.red
blueRed = candleColor ==  color.red and candleColor[1] == color.blue
greenPurpule = candleColor ==  color.fuchsia and candleColor[1] == color.lime
purpleGreen = candleColor ==  color.lime and candleColor[1] == color.fuchsia
bluePurpule = candleColor ==  color.fuchsia and candleColor[1] == color.blue
purpleBlue = candleColor ==  color.blue and candleColor[1] == color.fuchsia
alertcondition(redGreen, title='Red/Green Vector Candle Pattern', message='{{ticker}} Red/Green Vector Candle Pattern on the {{interval}}')
alertcondition(greenRed, title='Green/Red Vector Candle Pattern', message='{{ticker}} Green/Red Vector Candle Pattern on the {{interval}}')
alertcondition(redBlue, title='Red/Blue Vector Candle Pattern', message='{{ticker}} Red/Blue Vector Candle Pattern on the {{interval}}')
alertcondition(blueRed, title='Blue/Red Vector Candle Pattern', message='{{ticker}} Blue/Red Vector Candle Pattern on the {{interval}}')
alertcondition(greenPurpule, title='Green/Purple Vector Candle Pattern', message='{{ticker}} Green/Purple Vector Candle Pattern on the {{interval}}')
alertcondition(purpleGreen, title='Purple/Green Vector Candle Pattern', message='{{ticker}} Purple/Green Vector Candle Pattern on the {{interval}}')
alertcondition(bluePurpule, title='Blue/Purple Vector Candle Pattern', message='{{ticker}} Blue/Purple Vector Candle Pattern on the {{interval}}')
alertcondition(purpleBlue, title='Purple/Blue Vector Candle Pattern', message='{{ticker}} Purple/Blue Vector Candle Pattern on the {{interval}}')

Overview

Vector Candles compares each bar's volume with the average of the previous ten bars and also checks the product of spread and volume against the highest value in that window. Climax bars and above-average bars receive separate bull and bear colors. The excerpt shows no user inputs. Drawing is limited to intraday charts and uses security calls written to avoid lookahead.

Details

Published by

benso87 on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volume, Candlestick patterns

Markets

Any symbol

Timeframes

M1-M5, M15-H1

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

23 stars

Point-Clip Unified Indicator plots breakout and directional labels on the price chart. It scores volume spikes against a volume average, range or opening-range breaks, optional VWAP or session-anchored VWAP, fast and slow EMA trend, and a higher-timeframe EMA

Indicator v6 BreakoutVolume Repaints
Updated 3 weeks ago · Custom licence GitHub repository of Point-Clip Unified Indicator

Commitment Gauge

by harryguiacorn
219 stars

This indicator measures directional momentum by evaluating candlestick body proportions and volume over a user-defined lookback window. It computes the ratio of candle body to total range, weights the cumulative value by volume and absolute body size, and dete

Indicator v4 VolumeCandlestick patterns
Updated 1 year ago · None stated GitHub repository of Commitment Gauge

The Candle Pressure Index measures buying versus selling pressure from candle geometry and relative volume. Each bar combines close location, body ratio, and volume rank into a raw pressure value. An exponential moving average of that pressure forms the CPI os

Indicator v6 Oscillators & momentumVolume
Updated yesterday · MIT GitHub repository of Candle Pressure Index [WavesUnchained]

Calculates an Elastic Volume Weighted Moving Average (EVWMA), incorporating trading volume to dynamically adjust moving average responsiveness over a specified lookback length. It plots directly on the price chart as a single moving average line. Optional colo

Indicator v4 Moving averagesVolume
Updated 10 days ago · GPL-3.0 GitHub repository of Elastic Volume Weighted Moving Average
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

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