// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OskarGallard
//@version=6
indicator('Koncorde Plus', 'Koncorde [+]')
f_getPriceValue(_htf) =>
var value = 0.
if ta.change(time(_htf)) != 0
value := close[1]
value
value
f_crossingLevel(_curret, _level) =>
_level > _curret and _level < _curret[1] or _level < _curret and _level > _curret[1]
alarm(_cond, _message, _htfUser, _oncePerBarClose) =>
if _cond
alert(_message + '\n' + syminfo.ticker + ' Price (' + str.tostring(close, format.mintick) + '), Timeframe ' + _htfUser + '\n')
if _oncePerBarClose
alert(_message + '\n' + syminfo.ticker + ' Price (' + str.tostring(close, format.mintick) + '), Timeframe ' + _htfUser + '\n', alert.freq_once_per_bar_close)
g_pattern = 'Koncorde : Pattern 🐳 🆚 🐟'
show_K = input.bool(true, '⏩ Show Koncorde', inline = 'p0', group = g_pattern)
show_cero = input.bool(true, 'Zero Pattern', inline = 'p0', group = g_pattern)
char_up_cero = input.string('▲', '', inline = 'p0', group = g_pattern)
show_espejo = input.bool(true, 'Mirror Pattern', inline = 'p1', group = g_pattern)
col_espejo = input.color(color.new(color.aqua, 85), '', inline = 'p1', group = g_pattern)
show_oso = input.bool(false, 'Bear Hug Pattern', inline = 'p2', group = g_pattern)
col_oso = input.color(color.new(color.red, 85), '', inline = 'p2', group = g_pattern)
show_arpon = input.bool(true, 'Harpoon Pattern', inline = 'p3', group = g_pattern)
char_up_arp = input.string('↗️', '', inline = 'p3', group = g_pattern)
char_dn_arp = input.string('⇘', '', inline = 'p3', group = g_pattern)
show_primavera = input.bool(false, 'Spring Pattern', inline = 'p4', group = g_pattern)
char_up_primavera = input.string('▲', '', inline = 'p4', group = g_pattern)
show_cruces = input.bool(false, 'Crossing Pattern', inline = 'p5', group = g_pattern)
char_up_cruce = input.string('▲', '', inline = 'p5', group = g_pattern)
char_dn_cruce = input.string('▼', '', inline = 'p5', group = g_pattern)
show_macd = input.bool(true, '⏩ Display the MACD as dots at the top', inline = '0_macd')
show_macd3 = input.bool(false, '⏩ MACD Plot', inline = '0_macd')
show_macdv = input.bool(true, '⫸ Switch to MACD Normalized Volatility', inline = '1_macd')
show_rsi = input.bool(false, '⏩ Show RSI & MFI', inline = '0_rsi')
option_rsi = input.string('RSI', ' ⮞ Option', options = ['RSI', 'MFI', 'AVG(RSI, MFI)', 'Ultimate RSI'], inline = '0_rsi')
show_rsi_sig = input.bool(false, 'Use Signal Line', inline = '0_rsi')
show_stoc = input.bool(false, '⏩ Show Stochastic')
show_DVDI = input.bool(false, '⏩ Dual Volume Divergence Index', inline = '0_dv')
mode = input.string('Oscillator Mode', ' ⮞ Mode', inline = '0_dv', options = ['Cloud Mode', 'Oscillator Mode', 'Bar Counter Mode'])
show_delta = input.bool(false, '⏩ Show Volume Delta Arrows')
show_tsv = input.bool(false, '⏩ Show Enhanced Time Segmented Volume [TSV]')
group_stat = '⎆⎆ Statistic Panel'
chgStat = input.bool(false, '⮜ Performance || Distance to MA ⮞', inline = 'PD', group = group_stat, tooltip = 'Performance , displays values from the beginning of the month, week, year, etc\n\nDistance from/to MA - Multi TimeFrame Price Distance from/to MA')
pmaStat = input.bool(true, '', inline = 'PD', group = group_stat)
statSize = input.string('Small', 'Statistic Panel Text Size', options = ['Auto', 'Tiny', 'Small', 'Normal'], group = group_stat)
textSize = statSize == 'Small' ? size.small : statSize == 'Normal' ? size.normal : statSize == 'Auto' ? size.auto : size.tiny
maAlarm = input.bool(true, 'Enable Moving Average Alerts', group = group_stat, tooltip = 'MA alerts : price crossing ma levels detection')
type_ma1 = input.string('T3', 'MA 1', options = ['VIDYA', '2Pole Super Smoother', 'Ultimate Smoother', 'Smooth LSMA', 'T3', 'SMA', 'EMA', 'Wilder', 'ALMA', 'WMA', 'VWMA', 'D_SMA', 'D_EMA', 'D_WMA', 'VAMA', 'D_T3'], inline = 'ma1', group = group_stat)
length_ma1 = input.int(8, 'Length', minval = 1, inline = 'ma1', group = group_stat)
source_ma1 = input.source(hlcc4, 'Source', inline = 'ma1', group = group_stat)
type_ma2 = input.string('EMA', 'MA 2', options = ['VIDYA', '2Pole Super Smoother', 'Ultimate Smoother', 'Smooth LSMA', 'T3', 'SMA', 'EMA', 'Wilder', 'ALMA', 'WMA', 'VWMA', 'D_SMA', 'D_EMA', 'D_WMA', 'VAMA', 'D_T3'], inline = 'ma2', group = group_stat)
length_ma2 = input.int(55, 'Length', minval = 1, inline = 'ma2', group = group_stat)
source_ma2 = input.source(close, 'Source', inline = 'ma2', group = group_stat)
type_ma3 = input.string('SMA', 'MA 3', options = ['VIDYA', '2Pole Super Smoother', 'Ultimate Smoother', 'Smooth LSMA', 'T3', 'SMA', 'EMA', 'Wilder', 'ALMA', 'WMA', 'VWMA', 'D_SMA', 'D_EMA', 'D_WMA', 'VAMA', 'D_T3'], inline = 'ma3', group = group_stat)
length_ma3 = input.int(200, 'Length', minval = 1, inline = 'ma3', group = group_stat)
source_ma3 = input.source(close, 'Source', inline = 'ma3', group = group_stat)
g_trend = 'Koncorde Trend'
tprice = input.source(ohlc4, 'RSI, BB & Stoch Source', group = g_trend)
srcMfi = input.source(hlc3, 'MFI Source', group = g_trend)
len_mfi_rsi = input.int(14, 'MFI & RSI Length', 1, group = g_trend)
length_bb = input.int(25, 'BB Length', 1, inline = 'bb', group = g_trend)
mult_bb = input.float(2.0, 'BB Multiplier', 1, inline = 'bb', group = g_trend)
length_ma01 = input.int(15, 'MA Length', 1, inline = 'ma1', group = g_trend)
type_ma01 = input.string('EMA', 'Type', inline = 'ma1', group = g_trend, options = ['2Pole Super Smoother', 'Ultimate Smoother', 'Smooth LSMA', 'T3', 'VIDYA', 'SMA', 'EMA', 'Wilder', 'WMA', 'VWMA', 'ALMA', 'LSMA', 'HMA', 'VAMA', 'JMA', 'RSS_WMA'])
// VAMA factor
factor = 0.67//input.float(0.67, 'Factor (if VAMA)', minval = 0.01, step = 0.1, inline = 'v_l', group = g_trend)
// LSMA Offset
loff = 0//input.int(0, 'Offset (if LSMA)', minval = 0, inline = 'v_l', group = g_trend)
// ALMA Offset and Sigma
offs = 0.85//input.float(0.85, 'Offset (if ALMA)', step = 0.01, minval = 0, inline = 'alma', group = g_trend)
sigma = 6//input.int(6, 'Sigma (if ALMA)', minval = 0, inline = 'alma', group = g_trend)
// JMA
phaseJ = 50//input.int(50, 'Phase (if JMA)', inline = 'jma', group = g_trend)
powerJ = 2//input.int(2, 'Power (if JMA)', inline = 'jma', group = g_trend)
m_pvi_nvi = input.int(15, 'PVI & NVI Length', 1, group = 'Koncorde Volume')
longitudPVI = input.int(90, 'Min-Max Period [PVI]', 2, group = 'Koncorde Volume')
longitudNVI = input.int(90, 'Min-Max Period [NVI]', 2, group = 'Koncorde Volume')
group_macd = '⎆⎆ Moving Average Convergence Divergence [MACD]'
tool_atr = 'Used to gauge volatility to standardize MACD. Keep at the same value as the MACD Slow Length parameter for best results.'
macd_src = input.source(close, 'Source', inline = 'macd1', group = group_macd)
show_macd2 = input.bool(false, 'Show Bars Color', inline = 'macd1', group = group_macd)
macd_fast = input.int(12, 'Length: Fast', 1, inline = 'macd2', group = group_macd)
macd_slow = input.int(26, 'Slow', 2, inline = 'macd2', group = group_macd)
macd_sig = input.int(9, 'Signal', 1, inline = 'macd2', group = group_macd)
atr_length = input.int(26, 'ATR Length', 2, inline = 'macdv', group = group_macd, tooltip = tool_atr)
group_rsi = '⎆⎆ Relative Strength Index & Money Flow Index'
rsiLengthInput = input.int(14, 'Length', minval = 1, inline = 'rsi0', group = group_rsi)
rsiSourceInput = input.source(close, 'Source', inline = 'rsi0', group = group_rsi)
show_rsi2 = input.bool(false, 'Show Bars Color', inline = 'rsi0', group = group_rsi)
maTypeInput = input.string('EMA', 'MA Type', options = ['2Pole Super Smoother', 'Ultimate Smoother', 'Smooth LSMA', 'T3', 'D_T3', 'VIDYA', 'SMA', 'D_SMA', 'Wilder', 'EMA', 'D_EMA', 'ALMA', 'WMA', 'D_WMA', 'VWMA', 'VAMA'], inline = 'rsi1', group = group_rsi)
maLengthInput = input.int(14, 'MA Length', inline = 'rsi1', group = group_rsi)
obValue = input.float(80, 'Overbought', inline = 'rsi_o', group = group_rsi)
osValue = input.float(20, 'Oversold', inline = 'rsi_o', group = group_rsi)
group_stoc = '⎆⎆ Stochastic'
periodK = input.int(14, '%K Length', 1, group = group_stoc)
smoothK = input.int(7, '%K Smoothing', 1, group = group_stoc)
periodD = input.int(4, '%D Smoothing', 1, group = group_stoc)
ob_stoc = input.float(80, 'Overbought', inline = 'stoc_o', group = group_stoc)
os_stoc = input.float(20, 'Oversold', inline = 'stoc_o', group = group_stoc)
group_DVDI = '⎆⎆ Dual Volume Divergence Index'
show_bar_dvdi = input.bool(false, 'Show Bars Color', inline = 'extra2', group = group_DVDI)
src = input.source(close, 'Source', group = group_DVDI) // Source
// Sampling Period
per = input.int(55, 'Sampling Period', 1, group = group_DVDI)
smper = input.int(1, 'Smoothing Period', 1, group = group_DVDI)
group_delta = '⎆⎆ Volume Delta Arrows'
v_type = input.string('Cumulative Volume Delta', 'Volume Type', inline = 'delta0', group = group_delta, options = ['Cumulative Volume Delta', 'OBV', 'PVT', 'OBV+PVT', 'Delta+OBV', 'Delta+PVT', 'Delta+AccDist', 'OBV+PVT+AccDist'])
show_delta2 = input.bool(false, 'Show Bars Color', inline = 'delta0', group = group_delta)
fast_len = input.int(3, 'Fast MA', 1, inline = 'delta1', group = group_delta)
type_fast = input.string('Wilder', 'Type', inline = 'delta1', group = group_delta, options = ['VIDYA', '2Pole Super Smoother', 'Ultimate Smoother', 'Smooth LSMA', 'T3', 'D_T3', 'SMA', 'EMA', 'Wilder', 'WMA', 'ALMA', 'LSMA', 'HMA', 'JMA', 'RSS_WMA'])
slow_len = input.int(21, 'Slow MA', 1, inline = 'delta2', group = group_delta)
type_slow = input.string('EMA', 'Type', inline = 'delta2', group = group_delta, options = ['VIDYA', '2Pole Super Smoother', 'Ultimate Smoother', 'Smooth LSMA', 'T3', 'D_T3', 'SMA', 'EMA', 'Wilder', 'WMA', 'ALMA', 'LSMA', 'HMA', 'JMA', 'RSS_WMA'])
group_tsv = '⎆⎆ Enhanced Time Segmented Volume [TSV]'
len_tsv = input.int(13, 'Length', 3, inline = 'tsv2', group = group_tsv)
show_tsv2 = input.bool(false, 'Show Bars Color', inline = 'tsv2', group = group_tsv)
len_ma = input.int(7, 'MA Length', 1, inline = 'ma_tsv', group = group_tsv)
type_ma = input.string('SMA', 'Type', inline = 'ma_tsv', group = group_tsv, options = ['VIDYA', '2Pole Super Smoother', 'Ultimate Smoother', 'Smooth LSMA', 'T3', 'D_T3', 'SMA', 'EMA', 'Wilder', 'WMA', 'ALMA', 'LSMA', 'HMA', 'JMA', 'RSS_WMA'])
//__________________________________________________________
//_______________Definitions of Koncorde Plus_______________
pvi_media = ta.ema(ta.pvi, m_pvi_nvi)
pvi_max = ta.highest(pvi_media, longitudPVI)
pvi_min = ta.lowest(pvi_media, longitudPVI)
osc_pos = (ta.pvi - pvi_media) * 100 / (pvi_max - pvi_min)
nvi_media = ta.ema(ta.nvi, m_pvi_nvi)
nvi_max = ta.highest(nvi_media, longitudNVI)
nvi_min = ta.lowest(nvi_media, longitudNVI)
osc_neg = (ta.nvi - nvi_media) * 100 / (nvi_max - nvi_min)
// Tick Volume
tick = syminfo.mintick
rng = close - open
tickrng = tick
tickrng := math.abs(rng) < tick ? nz(tickrng[1]) : rng
tickvol = math.abs(tickrng) / tick
volumen = nz(volume) == 0 ? tickvol : volume
enhanced_vwma(_series, _length) =>
vmp = _series * volumen
VWMA = math.sum(vmp, _length) / math.sum(volumen, _length)
VWMA
// VAMA - Volume Adjusted Moving Average of @allanster
vama(_src, _len, _fct, _rul, _nvb) => // vama(source,length,factor,rule,sample)
tvb = 0 // total volume bars used in sample
tvb := _nvb == 0 ? nz(tvb[1]) + 1 : _nvb
tvs = _nvb == 0 ? ta.cum(volume) : math.sum(volume, _nvb) // total volume in sample
v2i = volume / (tvs / tvb * _fct) // ratio of volume to increments of volume
wtd = _src * v2i // weighted prices
nmb = 1 // initialize number of bars summed back
wtdSumB = 0.0 // initialize weighted prices summed back
v2iSumB = 0.0 // initialize ratio of volume to increments of volume summed back
for i = 1 to _len * 10 by 1 // set artificial cap for strict to VAMA length * 10 to help reduce edge case timeout errors
strict = _rul ? false : i == _len // strict rule N bars' v2i ratios >= vama length, else <= vama length
wtdSumB := wtdSumB + nz(wtd[i - 1]) // increment number of bars' weighted prices summed back
v2iSumB := v2iSumB + nz(v2i[i - 1]) // increment number of bars' v2i's summed back
if v2iSumB >= _len or strict // if chosen rule met
break // break (exit loop)
nmb := nmb + 1 // increment number of bars summed back counter
nmb
//nmb // number of bars summed back to fulfill volume requirements or vama length
//wtdSumB // number of bars' weighted prices summed back
//v2iSumB // number of bars' v2i's summed back
vama = (wtdSumB - (v2iSumB - _len) * _src[nmb]) / _len // volume adjusted moving average
vama
// JMA - Jurik Moving Average of @everget
jma(src, length, power, phase) =>
phaseRatio = phase < -100 ? 0.5 : phase > 100 ? 2.5 : phase / 100 + 1.5
beta = 0.45 * (length - 1) / (0.45 * (length - 1) + 2)
alpha = math.pow(beta, power)
Jma = 0.0
e0 = 0.0
e0 := (1 - alpha) * src + alpha * nz(e0[1])
e1 = 0.0
e1 := (src - e0) * (1 - beta) + beta * nz(e1[1])
e2 = 0.0
e2 := (e0 + phaseRatio * e1 - nz(Jma[1])) * math.pow(1 - alpha, 2) + math.pow(alpha, 2) * nz(e2[1])
Jma := e2 + nz(Jma[1])
Jma
// ALMA - Arnaud Legoux Moving Average of @kurtsmock
enhanced_alma(_series, _length, _offset, _sigma) =>
length = int(_length) // Floating point protection
numerator = 0.0
denominator = 0.0
m = _offset * (length - 1)
s = length / _sigma
for i = 0 to length - 1 by 1
weight = math.exp(-((i - m) * (i - m)) / (2 * s * s))
numerator := numerator + weight * _series[length - 1 - i]
denominator := denominator + weight
denominator
numerator / denominator
// RSS_WMA of @RedKTrader
f_LazyLine(_data, _length) =>
w1 = 0
w2 = 0
w3 = 0
L1 = 0.0
L2 = 0.0
L3 = 0.0
w = _length / 3
if _length > 2
w2 := math.round(w)
w1 := math.round((_length - w2) / 2)
w3 := int((_length - w2) / 2)
L1 := ta.wma(_data, w1)
L2 := ta.wma(L1, w2)
L3 := ta.wma(L2, w3)
L3
else
L3 := _data
L3
L3
//T3 Moving Average based on the article 'Smoothing Techniques For More Accurate Signals' by Tim Tillson
f_t3(src, len) =>
x1 = ta.ema(src, len) //(hlcc, 8)
x2 = ta.ema(x1, len)
x3 = ta.ema(x2, len)
x4 = ta.ema(x3, len)
x5 = ta.ema(x4, len)
x6 = ta.ema(x5, len)
b = 0.7 //Volume Factor
c1 = -math.pow(b, 3)
c2 = 3 * math.pow(b, 2) + 3 * math.pow(b, 3)
c3 = -6 * math.pow(b, 2) - 3 * b - 3 * math.pow(b, 3)
c4 = 1 + 3 * b + math.pow(b, 3) + 3 * math.pow(b, 2)
c1 * x6 + c2 * x5 + c3 * x4 + c4 * x3
// 2PSS - Ehlers 2 Pole Super Smoother
f_2pss(_src, _length) =>
var _a0 = math.sqrt(2) * math.pi / _length
var _a1 = math.exp(-_a0)
var _b0 = 2 * _a1 * math.cos(_a0)
var _c2 = -math.pow(_a1, 2)
var _c1 = _b0
var _c0 = 1 - _c1 - _c2
var _2pss = 0.0
_src1 = nz(_src[1], _src)
_src2 = nz(_src[2], _src1)
_2pss := _c0 * _src + _c1 * nz(_2pss[1], _src1) + _c2 * nz(_2pss[2], _src2)
_2pss
// Variable Index Dynamic Average (VIDYA) by Tushar Chande
VIDYA(src, length) =>
valpha = 2 / (length + 1)
vud1 = src > src[1] ? src - src[1] : 0
vdd1 = src < src[1] ? src[1] - src : 0
vUD = math.sum(vud1, 9)
vDD = math.sum(vdd1, 9)
vCMO = nz((vUD - vDD) / (vUD + vDD))
VAR = 0.0
VAR := nz(valpha * math.abs(vCMO) * src) + (1 - valpha * math.abs(vCMO)) * nz(VAR[1])
VAR
// https://www.tradingview.com/script/X67OSwqc-TASC-2024-04-The-Ultimate-Smoother/
// @function The UltimateSmoother is a filter created
// by subtracting the response of a high-pass
// filter from that of an all-pass filter.
// @returns Smoothed series.
UltimateSmoother(float src, int period) =>
float a1 = math.exp(-1.414 * math.pi / period)
float c2 = 2.0 * a1 * math.cos(1.414 * math.pi / period)
float c3 = -a1 * a1
float c1 = (1.0 + c2 - c3) / 4.0
float us = src
if bar_index >= 4
us := (1.0 - c1) * src + (2.0 * c1 - c2) * src[1] - (c1 + c3) * src[2] + c2 * nz(us[1]) + c3 * nz(us[2])
us
us
ma(_type, _source, _length) =>
switch _type
'SMA' => ta.sma(_source, _length)
'EMA' => ta.ema(_source, _length)
'WMA' => ta.wma(_source, _length)
'VWMA' => enhanced_vwma(_source, _length)
'LSMA' => ta.linreg(_source, _length, loff) // Least Squares
'ALMA' => enhanced_alma(_source, _length, offs, sigma)
'HMA' => ta.hma(_source, _length)
'VAMA' => vama(_source, _length, factor, true, 0)
'JMA' => jma(_source, _length, powerJ, phaseJ)
'Wilder' =>
wild = _source // Wilder's moving average
wild := nz(wild[1]) + (_source - nz(wild[1])) / _length
wild
'RSS_WMA' => f_LazyLine(_source, _length)
'D_SMA' => ta.sma(ta.sma(_source, _length), _length)
'D_EMA' => ta.ema(ta.ema(_source, _length), _length)
'D_WMA' => ta.wma(ta.wma(_source, _length), _length)
'T3' => f_t3(_source, _length)
'Ultimate Smoother' => UltimateSmoother(_source, _length)
'Smooth LSMA' =>
lsma = ta.linreg(_source, _length, 0)
slsma = lsma - (lsma - ta.linreg(lsma, _length, 0))
slsma
'2Pole Super Smoother' => f_2pss(_source, _length)
'D_T3' => f_t3(f_t3(_source, _length), _length)
'VIDYA' => VIDYA(_source, _length)
f_bb(source, length) =>
basis = ta.sma(source, length)
dev = mult_bb * ta.stdev(source, length)
upper = basis + dev // Upper Band
lower = basis - dev // Lower Band
avg_up_low = math.avg(upper, lower)
diff_up_low = upper - lower
(source - avg_up_low) / diff_up_low * 100
f_stoch(src, length, smoothFastD) =>
ll = ta.lowest(low, length)
hh = ta.highest(high, length)
k = 100 * (src - ll) / (hh - ll)
ta.sma(k, smoothFastD) // enhanced_alma(k, smoothFastD, 0.85, 6)
rsi_valor = ta.rsi(tprice, len_mfi_rsi)
mfi_valor = ta.mfi(srcMfi, len_mfi_rsi)
osc_bb = f_bb(tprice, length_bb)
stoc = f_stoch(tprice, 21, 3)
tendencia = (rsi_valor + mfi_valor + osc_bb + stoc / 3) / 2 //math.avg(rsi_valor, mfi_valor, osc_bb, stoc)
tiburones = ta.sma(osc_neg, 1)
pececillos = tendencia + osc_pos
ma_trend = ma(type_ma01, tendencia, length_ma01) //ta.ema(tendencia, length_ma01)
patron_espejo = pececillos < 0 and tiburones > 0
patron_oso = pececillos > 0 and tiburones < 0 and pececillos >= tendencia
patron_cero = ta.crossover(tendencia, 0)
cross_up_trend = ta.crossover(tendencia, ma_trend)
cross_dn_trend = ta.crossunder(tendencia, ma_trend)
patron_primavera = ta.crossover(tendencia, ma_trend) and pececillos > tendencia //or (ta.crossover(pececillos, tendencia) and pececillos >0)
cross_tiburon_ma = ta.crossover(tiburones, ma_trend)
cross_up_shark = cross_tiburon_ma and pececillos < 0 and tiburones > 0
cross_dn_shark = ta.crossunder(tiburones, 0) and pececillos > tendencia and pececillos > ma_trend
cross_up_shark2 = cross_tiburon_ma and tendencia < ma_trend and pececillos > 0
plot(show_K ? pececillos : na, 'Minnows', pececillos > 0 ? #05FF68 : #009929, 1, plot.style_columns)
plot(show_K ? tiburones : na, 'Shark', tiburones > 0 ? #0E55FF : #003785, 1, plot.style_columns) //#00B0F6
plot(show_K ? ma_trend : na, 'MA of Trend', #FF001E, 2, plot.style_line)
//hline(show_K ? 0 : na, "Center Line", #FAF5A5, hline.style_dotted)
plot(show_K ? tendencia : na, 'Trend', tendencia > tendencia[1] ? #8D4925 : #320000, 2, plot.style_line)
plot(show_K ? tendencia : na, 'Trend', tendencia > tendencia[1] ? color.new(#8D4925, 70) : color.new(#320000, 45), 1, plot.style_columns, display = display.pane)
//______________________________________________________________________________
// Dual Volume Divergence Index - DVDI of @DonovanWall
// https://www.tradingview.com/script/p2tfpKK3-Dual-Volume-Divergence-Index-DW/
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Dual Volume Divergence Index
roc_x = ta.roc(src, 1)
dvdi(x, t1, t2, v) =>
pvi = x
pvi := v > v[1] ? nz(pvi[1]) + roc_x : nz(pvi[1])
psig = ta.ema(pvi, t1)
PDIV = ta.ema(pvi - psig, t2)
nvi = x
nvi := v < v[1] ? nz(nvi[1]) - roc_x : nz(nvi[1])
nsig = ta.ema(nvi, t1)
NDIV = ta.ema(nvi - nsig, t2)
DVDIO = PDIV - NDIV
[PDIV, NDIV, DVDIO]
[pdiv, ndiv, dvdio] = dvdi(src, per, smper, volumen)
// DVDI Bar Counter
cross_up = ta.barssince(ta.crossover(dvdio, 0))
cross_dn = ta.barssince(ta.crossunder(dvdio, 0))
pdbars = dvdio > 0 ? cross_up + 1 : 0
ndbars = dvdio < 0 ? cross_dn + 1 : 0
// Divergence Color
color1 = pdiv > ndiv and pdiv > 0 ? #05ffa6 : pdiv > ndiv and pdiv <= 0 ? #00945f : ndiv > pdiv and ndiv > 0 ? #ff0a70 : ndiv > pdiv and ndiv <= 0 ? #990040 : #cccccc
color2 = dvdio > 0 and dvdio > dvdio[1] ? #05ffa6 : dvdio > 0 and dvdio <= dvdio[1] ? #00945f : dvdio < 0 and dvdio < dvdio[1] ? #ff0a70 : dvdio < 0 and dvdio >= dvdio[1] ? #990040 : #cccccc
color3 = pdbars > 0 and src > src[1] ? #05ffa6 : pdbars > 0 and src <= src[1] ? #00945f : ndbars > 0 and src < src[1] ? #ff0a70 : ndbars > 0 and src >= src[1] ? #990040 : #cccccc
barcolor = mode == 'Cloud Mode' ? color1 : mode == 'Oscillator Mode' ? color2 : color3
color1_60 = pdiv > ndiv and pdiv > 0 ? color.new(#05ffa6, 60) : pdiv > ndiv and pdiv <= 0 ? color.new(#00945f, 60) : ndiv > pdiv and ndiv > 0 ? color.new(#ff0a70, 60) : ndiv > pdiv and ndiv <= 0 ? color.new(#990040, 60) : color.new(#cccccc, 60)
color2_60 = dvdio > 0 and dvdio > dvdio[1] ? color.new(#05ffa6, 60) : dvdio > 0 and dvdio <= dvdio[1] ? color.new(#00945f, 60) : dvdio < 0 and dvdio < dvdio[1] ? color.new(#ff0a70, 60) : dvdio < 0 and dvdio >= dvdio[1] ? color.new(#990040, 60) : color.new(#cccccc, 60)
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Plots
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Dual Index Plots
pplot = plot(show_DVDI and mode == 'Cloud Mode' ? pdiv : na, 'PVI Divergence', #05FFA6)
nplot = plot(show_DVDI and mode == 'Cloud Mode' ? ndiv : na, 'NVI Divergence', #FF0A70)
// Dual Index Fill
fill(pplot, nplot, color1_60, 'Cloud Fill')
//Oscillator Plot
oplot = plot(show_DVDI and mode == 'Oscillator Mode' ? dvdio : na, 'DVDI Oscillator', color2)
// Oscillator Fill
centplot = plot(0, 'Index Center', display = display.none, editable = false) // Index Center
fill(oplot, centplot, color2_60, 'Oscillator Fill')
// Bar Counter Plot
pdbarsplot = plot(show_DVDI and mode == 'Bar Counter Mode' ? pdbars : na, 'Positive Dominant Bar Count', #05FFA6)
ndbarsplot = plot(show_DVDI and mode == 'Bar Counter Mode' ? ndbars : na, 'Negative Dominant Bar Count', #FF0A70)
// Bar Counter Fill
fill(pdbarsplot, centplot, color.new(#05FFA6, 60), 'Positive Dominant Bar Count Fill')
fill(ndbarsplot, centplot, color.new(#FF0A70, 60), 'Negative Dominant Bar Count Fill')
// Bar Colors
barcolor(show_bar_dvdi ? barcolor : na, title = 'DVDI Bars Color')
//____________________________________________________________________________
// Enhanced Time Segmented Volume of @StephXAGs
// https://www.tradingview.com/script/672uPH9q-Enhanced-Time-Segmented-Volume/
t = math.sum(close > close[1] ? volume * (close - close[1]) : close < close[1] ? volume * (close - close[1]) : 0, len_tsv)
m = ma(type_ma, t, len_ma)
PAL = t > m and t > 0
PAL_fail = t < m and t > 0
PAS = t < m and t < 0
PAS_fail = t > m and t < 0
plotshape(show_tsv and PAL, 'Price Action Long', shape.square, location.bottom, color.new(#04E604, 5), size = size.auto)
plotshape(show_tsv and PAS, 'Price Action Short', shape.square, location.bottom, color.new(#E60404, 5), size = size.auto)
plotshape(show_tsv and PAL_fail, 'Price Action Long - FAILURE', shape.xcross, location.bottom, color.new(#027302, 60), size = size.auto)
plotshape(show_tsv and PAS_fail, 'Price Action Short - FAILURE', shape.xcross, location.bottom, color.new(#730202, 60), size = size.auto)
color_tsv = PAL ? color.new(#04E604, 10) : PAS ? color.new(#E60404, 10) : PAL_fail ? color.new(#027302, 10) : PAS_fail ? color.new(#730202, 10) : #EFEFBF
barcolor(show_tsv2 ? color_tsv : na, title = 'TSV Bars Color')
//____________________________________________Delta Arrows____________________________________________
tw = high - math.max(open, close)
bw = math.min(open, close) - low
body = math.abs(close - open)
f_rate(cond) =>
ret = 0.5 * (tw + bw + (cond ? 2 * body : 0)) / (tw + bw + body)
ret := nz(ret) == 0 ? 0.5 : ret
ret
delta_up = volume * f_rate(open <= close)
delta_down = volume * f_rate(open > close)
delta = close >= open ? delta_up : -delta_down
cum_delta = switch v_type
'Cumulative Volume Delta' => ta.cum(delta)
'OBV' => ta.obv
'PVT' => ta.pvt
'OBV+PVT' => math.avg(ta.obv, ta.pvt)
'OBV+PVT+AccDist' => math.avg(ta.obv, ta.pvt, ta.accdist)
'Delta+AccDist' => math.avg(delta, ta.accdist)
'Delta+OBV' => math.avg(delta, ta.obv)
'Delta+PVT' => math.avg(delta, ta.pvt)
ma_fast = ma(type_fast, cum_delta, fast_len)
ma_slow = ma(type_slow, cum_delta, slow_len)
delta_osc = ma_fast - ma_slow
sc1 = delta_osc >= 0
sc2 = delta_osc < 0
sc3 = delta_osc >= delta_osc[1]
sc4 = delta_osc < delta_osc[1]
col_delta_up = sc1 and sc3 ? #8080FF : sc1 and sc4 ? #40407F : #EFEFBF
col_delta_dn = sc2 and sc4 ? #FF8080 : sc2 and sc3 ? #7F4040 : #EFEFBF
color_delta = delta_osc >= 0 ? col_delta_up : col_delta_dn
plotshape(show_delta and delta_osc >= 0, 'Up Delta', shape.triangleup, location.bottom, col_delta_up)
plotshape(show_delta and delta_osc < 0, 'Down Delta', shape.triangledown, location.bottom, col_delta_dn)
barcolor(show_delta2 ? color_delta : na, title = 'Delta Bars Color')
//____________________________________________MACD____________________________________________
[macd_line, macd_signal, _] = ta.macd(macd_src, macd_fast, macd_slow, macd_sig)
// MACD-V: Volatility Normalised Momentum of @Mik3Christ3ns3n
// https://www.tradingview.com/script/CE4EqZ1A-MACD-V-Volatility-Normalized-Momentum/
// https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4099617
macdv_line = (ta.ema(macd_src, macd_fast) - ta.ema(macd_src, macd_slow)) / ta.atr(atr_length) * 100
color cian = color.new(#38F5E9, 0)
color cian_oscuro = color.new(#1C7A74, 0)
color pink = color.new(#F7709D, 0)
color pink_oscuro = color.new(#7B384E, 0)
char_dot = '◍'
char_dot_red = '🔴'
char_dot_blue = '🔵'
color color_up = macd_line >= macd_signal ? cian : cian_oscuro
color color_dn = macd_line <= macd_signal ? pink : pink_oscuro
color color_macd = macd_line >= 0 ? color_up : color_dn
color color_up_v = macdv_line >= 150 ? color.blue : macdv_line >= 50 ? cian : cian_oscuro
color color_dn_v = macdv_line <= -150 ? color.red : macdv_line <= -50 ? pink : pink_oscuro
color color_macdv = macdv_line >= 0 ? color_up_v : color_dn_v
color color_m = show_macdv ? color_macdv : color_macd
area_macd = show_macdv ? macdv_line : macd_line
plot(show_macd3 ? area_macd : na, 'MACD Area', color_m, 2, plot.style_histogram)
plot(show_macd3 and not show_macdv ? macd_signal : na, 'MACD Siganal', color.new(#DBDB78, 40), 2)
plotchar(show_macd ? macd_line : na, 'MACD', char_dot, location.top, color_m)
plotchar(show_macdv and macdv_line >= 150 ? macdv_line : na, 'MACD-V OverBought', char_dot_blue, location.top, color.blue)
hline(show_macd3 and show_macdv ? 150 : na, 'MACD-V: Upper Band', color = color.new(#EFEFBF, 50), linestyle = hline.style_dotted)
hline(show_macd3 and show_macdv ? 50 : na, 'MACD-V: Upper Band', color = color.new(#EFEFBF, 50), linestyle = hline.style_dotted)
plotchar(show_macdv and macdv_line <= -150 ? macdv_line : na, 'MACD-V OverSold', char_dot_red, location.top, color.red)
hline(show_macd3 and show_macdv ? -50 : na, 'MACD-V: Lower Band', color = color.new(#EFEFBF, 50), linestyle = hline.style_dotted)
hline(show_macd3 and show_macdv ? -150 : na, 'MACD-V: Lower Band', color = color.new(#EFEFBF, 50), linestyle = hline.style_dotted)
barcolor(show_macd2 ? color_m : na, title = 'MACD Bars Color')
//____________________________________________Stochastic____________________________________________
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)
color color_fill_stoc = show_stoc and not show_rsi ? (k >= d ? color.new(#00BCD4, 85) : color.new(#FF9800, 85)) : na
h0 = plot(show_stoc ? k : na, '%K', color.new(#00BCD4, 35), 2) // #2962FF
h1 = plot(show_stoc ? d : na, '%D', #FF9800) // #FF6D00
hline(show_stoc ? ob_stoc : na, 'Upper Band', color = color.new(#EFEFBF, 50), linestyle = hline.style_dotted)
hline(show_stoc or show_rsi? 50 : na, 'Middle Band', color = color.new(#EFEFBF, 50), linestyle = hline.style_dotted)
hline(show_stoc ? os_stoc : na, 'Lower Band', color = color.new(#EFEFBF, 50), linestyle = hline.style_dotted)
fill(h0, h1, color = color_fill_stoc, title = "Stochastic Background")
//____________________________________________Relative Strength Index___________________________________________
// Ultimate RSI of @LuxAlgo
// https://www.tradingview.com/script/17Jj7Vcg-Ultimate-RSI-LuxAlgo/
upper = ta.highest(rsiSourceInput, rsiLengthInput)
lower = ta.lowest(rsiSourceInput, rsiLengthInput)
r = upper - lower
diff = upper > upper[1] ? r : lower < lower[1] ? -r : rsiSourceInput - rsiSourceInput[1]
num = ta.rma(diff, rsiLengthInput)
den = ta.rma(math.abs(diff), rsiLengthInput)
u_rsi = num / den * 50 + 50
rsi = switch option_rsi
'RSI' => ta.rsi(rsiSourceInput, rsiLengthInput)
'MFI' => ta.mfi(rsiSourceInput, rsiLengthInput)
'AVG(RSI, MFI)' => math.avg(ta.rsi(close, rsiLengthInput), ta.mfi(hlc3, rsiLengthInput))
'Ultimate RSI' => u_rsi
rsiMA = ma(maTypeInput, rsi, maLengthInput)
color color_rsi_up = #64FFDA
color color_rsi_up2 = #00796b
color color_rsi_dn = #F43E32
color color_rsi_dn2 = #B71C1C
color color_rsi = rsi >= 50 ? (rsi >= rsi[1] ? color_rsi_up : color_rsi_up2) : (rsi < rsi[1] ? color_rsi_dn : color_rsi_dn2)
rsiPlot = plot(show_rsi ? rsi : na, 'RSI', color_rsi, 1)
plot(show_rsi and show_rsi_sig ? rsiMA : na, 'RSI-based MA', #DBDB78)
plot(show_rsi and not show_stoc ? obValue : na, 'RSI Upper Band', color.new(color_rsi_dn, 50), 2)
//hline(show_rsi and not show_stoc ? 50 : na, 'RSI Middle Band', color = color.silver, linestyle = hline.style_dotted)
plot(show_rsi and not show_stoc ? osValue : na, 'RSI Lower Band', color.new(color_rsi_up, 50), 2)
midLinePlot = plot(50, color = na, editable = false, display = display.none)
fill(rsiPlot, midLinePlot, 100, 50, top_color = color.new(color_rsi_up, 0), bottom_color = color.new(color_rsi_up, 100), title = 'Overbought Gradient Fill')
fill(rsiPlot, midLinePlot, 50, 0, top_color = color.new(color_rsi_dn, 100), bottom_color = color.new(color_rsi_dn, 0), title = 'Oversold Gradient Fill')
barcolor(show_rsi2 ? color_rsi : na, title = 'RSI Bars Color')
// Divergence ------------------------------------------------------------------------------
lookbackRight = 5
lookbackLeft = 5
rangeUpper = 60
rangeLower = 5
bearColor = color.red
bullColor = color.green
textColor = #FFFFFF
textColor2 = #000000
noneColor = color.new(color.white, 100)
indicador = show_rsi ? rsi : show_stoc ? k : show_macd3 ? area_macd : show_DVDI and mode == 'Oscillator Mode' ? dvdio : na
showDivergence = na(indicador) ? false : true
not_label = not(show_rsi and show_stoc)
plFound = na(ta.pivotlow(indicador, lookbackLeft, lookbackRight)) ? false : true
phFound = na(ta.pivothigh(indicador, lookbackLeft, lookbackRight)) ? false : true
_inRange(cond) =>
bars = ta.barssince(cond == true)
rangeLower <= bars and bars <= rangeUpper
//------------------------------------------------------------------------------
// Regular Bullish
// Higher Low
range_pl = _inRange(plFound[1])
indiHL = indicador[lookbackRight] > ta.valuewhen(plFound, indicador[lookbackRight], 1) and range_pl
// Price: Lower Low
priceLL = low[lookbackRight] < ta.valuewhen(plFound, low[lookbackRight], 1)
bullCondAlert = priceLL and indiHL and plFound
bullCond = showDivergence and bullCondAlert
plot(plFound ? indicador[lookbackRight] : na, offset = -lookbackRight, title = 'Regular Bullish', linewidth = 2, color = bullCond ? bullColor : noneColor, display = display.pane)
plotshape(bullCond and not_label ? indicador[lookbackRight] : na, offset = -lookbackRight, title = 'Regular Bullish Label', text = ' R ', style = shape.labelup, location = location.absolute, color = bullColor, textcolor = textColor2)
//------------------------------------------------------------------------------
// Regular Bearish
// Lower High
range_ph = _inRange(phFound[1])
indiLH = indicador[lookbackRight] < ta.valuewhen(phFound, indicador[lookbackRight], 1) and range_ph
// Price: Higher High
priceHH = high[lookbackRight] > ta.valuewhen(phFound, high[lookbackRight], 1)
bearCondAlert = priceHH and indiLH and phFound
bearCond = showDivergence and bearCondAlert
plot(phFound ? indicador[lookbackRight] : na, offset = -lookbackRight, title = 'Regular Bearish', linewidth = 2, color = bearCond ? bearColor : noneColor, display = display.pane)
plotshape(bearCond and not_label ? indicador[lookbackRight] : na, offset = -lookbackRight, title = 'Regular Bearish Label', text = ' R ', style = shape.labeldown, location = location.absolute, color = bearColor, textcolor = textColor)
alertcondition(bullCondAlert, title = 'Regular Bullish Divergence', message = 'Found a new Regular Bullish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.')
alertcondition(bearCondAlert, title = 'Regular Bearish Divergence', message = 'Found a new Regular Bearish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.')
//____________________________________________Pattern____________________________________________
plotchar(show_cruces and cross_up_trend, 'Crossover', char_up_cruce, location.bottom, color.new(#64FFDA, 55), size = size.tiny)
plotchar(show_cruces and cross_dn_trend, 'Crossunder', char_dn_cruce, location.top, color.new(#F43E32, 55), size = size.tiny)
plotchar(show_cero and patron_cero, 'Zero Pattern', char_up_cero, location.bottom, color.new(#FFCC99, 35), size = size.tiny)
plotchar(show_primavera and patron_primavera, 'Spring Pattern', char_up_primavera, location.bottom, color.new(#80FF00, 45), size = size.tiny)
plotchar(show_arpon and cross_up_shark, 'Harpoon Pattern', char_up_arp, location.bottom, color.new(#00FFFF, 0), size = size.tiny)
plotchar(show_arpon and cross_dn_shark , 'Exit Harpoon Pattern', char_dn_arp, location.top, color.new(#FF4500, 10), size = size.tiny)
plotchar(show_arpon and cross_up_shark2, 'Weak Harpoon Pattern', '⇗', location.bottom, color.new(#0475E6, 10), size = size.tiny)
bgcolor(show_espejo and patron_espejo ? col_espejo : na, title = 'Mirror Pattern')
bgcolor(show_oso and patron_oso ? col_oso : na, title = 'Bear Hug Pattern')
//______________________________________________________________________________
// Performance Table by @dgtrd
//______________________________________________________________________________
sma20 = ma(type_ma1, source_ma1, length_ma1)
sma50 = ma(type_ma2, source_ma2, length_ma2)
sma200 = ma(type_ma3, source_ma2, length_ma3)
txt_ma1 = type_ma1 + str.tostring(length_ma1)
txt_ma2 = type_ma2 + str.tostring(length_ma2)
txt_ma3 = type_ma3 + str.tostring(length_ma3)
if maAlarm
alarm(f_crossingLevel(close, sma20), 'Price crossing current tf ' + txt_ma1 + '(' + str.tostring(sma20, format.mintick) + ')', timeframe.period, true)
alarm(f_crossingLevel(close, sma50), 'Price crossing current tf ' + txt_ma2 + '(' + str.tostring(sma50, format.mintick) + ')', timeframe.period, true)
alarm(f_crossingLevel(close, sma200), 'Price crossing current tf ' + txt_ma3 + '(' + str.tostring(sma200, format.mintick) + ')', timeframe.period, true)
color upColor = #26A69A
color dnColor = #EF5350
color naColor = color.blue
color upColor2 = #00FF98
color dnColor2 = #FF9800
dROR = (close / f_getPriceValue('D') - 1) * 100
wROR = (close / f_getPriceValue('W') - 1) * 100
mROR = (close / f_getPriceValue('M') - 1) * 100
qROR = (close / f_getPriceValue('3M') - 1) * 100
yROR = (close / f_getPriceValue('12M') - 1) * 100
var float q1 = na
var float q2 = na
var float q3 = na
var float q4 = na
if month < 4
q1 := qROR
q2 := na
q3 := na
q4 := na
q4
else if month > 3 and month < 7
q2 := qROR
q2
else if month > 6 and month < 10
q3 := qROR
q3
else if month > 9
q4 := qROR
q4
var float yROR1 = na
var float yROR2 = na
var float yROR3 = na
var int yr1 = na
var int yr2 = na
var int yr3 = na
if ta.change(time('12M')) != 0
yROR3 := yROR2
yr3 := yr2
yROR2 := yROR1
yr2 := yr1
yROR1 := yROR[1]
yr1 := year[1]
yr1
var table change = table.new(position.top_right, 4, 10, border_width = 3)
if barstate.islast and chgStat and chart.is_standard
table.cell(change, 0, 0, 'PERF', text_color = naColor, bgcolor = color.new(naColor, 80), text_halign = text.align_left, text_size = textSize)
if not timeframe.isweekly and not timeframe.ismonthly
table.cell(change, 1, 0, str.tostring(dROR, '#.##') + '%\nDTD', text_color = dROR > 0 ? upColor2 : dnColor2, bgcolor = dROR > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize, tooltip = 'Day to Date')
if not timeframe.ismonthly
table.cell(change, 2, 0, na(wROR) ? '-\nWTD' : str.tostring(wROR, '#.##') + '%\nWTD', text_color = na(wROR) ? naColor : wROR > 0 ? upColor2 : dnColor2, bgcolor = na(wROR) ? color.new(naColor, 80) : wROR > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize, tooltip = 'Week to Date')
table.cell(change, 3, 0, na(mROR) ? '-\nMTD' : str.tostring(mROR, '#.##') + '%\nMTD', text_color = na(mROR) ? naColor : mROR > 0 ? upColor2 : dnColor2, bgcolor = na(mROR) ? color.new(naColor, 80) : mROR > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize, tooltip = 'Month to Date')
if not na(q1) and not na(q2) and not na(q3) and not na(q4)
table.cell(change, 0, 1, na(q1) ? '-\nQ1' : str.tostring(q1, '#.##') + '%\nQ1', text_color = na(q1) ? naColor : q1 > 0 ? upColor2 : dnColor2, bgcolor = na(q1) ? color.new(naColor, 80) : q1 > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize, tooltip = '1st Quarter of ' + str.tostring(year))
table.cell(change, 1, 1, na(q2) ? '-\nQ2' : str.tostring(q2, '#.##') + '%\nQ2', text_color = na(q2) ? naColor : q2 > 0 ? upColor2 : dnColor2, bgcolor = na(q2) ? color.new(naColor, 80) : q2 > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize, tooltip = '2nd Quarter of ' + str.tostring(year))
table.cell(change, 2, 1, na(q3) ? '-\nQ3' : str.tostring(q3, '#.##') + '%\nQ3', text_color = na(q3) ? naColor : q3 > 0 ? upColor2 : dnColor2, bgcolor = na(q3) ? color.new(naColor, 80) : q3 > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize, tooltip = '3rd Quarter of ' + str.tostring(year))
table.cell(change, 3, 1, na(q4) ? '-\nQ4' : str.tostring(q4, '#.##') + '%\nQ4', text_color = na(q4) ? naColor : q4 > 0 ? upColor2 : dnColor2, bgcolor = na(q4) ? color.new(naColor, 80) : q4 > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize, tooltip = '4th Quarter of ' + str.tostring(year))
if not na(yROR)
table.cell(change, 3, 2, str.tostring(yROR, '#.##') + '%\n' + str.tostring(year), text_color = yROR > 0 ? upColor2 : dnColor2, bgcolor = yROR > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize, tooltip = str.tostring(year) + ' Year to Date')
table.cell(change, 2, 2, na(yROR1) ? '-\n-' : str.tostring(yROR1, '#.##') + '%\n' + str.tostring(yr1), text_color = na(yROR1) ? naColor : yROR1 > 0 ? upColor2 : dnColor2, bgcolor = na(yROR1) ? color.new(naColor, 80) : yROR1 > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize, tooltip = na(yROR1) and na(yr1) ? '' : str.tostring(yr1) + ' Rate of Return')
table.cell(change, 1, 2, na(yROR2) ? '-\n-' : str.tostring(yROR2, '#.##') + '%\n' + str.tostring(yr2), text_color = na(yROR2) ? naColor : yROR2 > 0 ? upColor2 : dnColor2, bgcolor = na(yROR2) ? color.new(naColor, 80) : yROR2 > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize, tooltip = na(yROR2) and na(yr2) ? '' : str.tostring(yr2) + ' Rate of Return')
table.cell(change, 0, 2, na(yROR3) ? '-\n-' : str.tostring(yROR3, '#.##') + '%\n' + str.tostring(yr3), text_color = na(yROR3) ? naColor : yROR3 > 0 ? upColor2 : dnColor2, bgcolor = na(yROR3) ? color.new(naColor, 80) : yROR3 > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize, tooltip = na(yROR3) and na(yr3) ? '' : str.tostring(yr3) + ' Rate of Return')
pma20 = (source_ma1 / sma20 - 1) * 100
pma50 = (source_ma2 / sma50 - 1) * 100
pma200 = (source_ma3 / sma200 - 1) * 100
[pma204h, pma504h, pma2004h] = request.security(syminfo.tickerid, '240', [pma20, pma50, pma200])
[pma20d, pma50d, pma200d] = request.security(syminfo.tickerid, 'D', [pma20, pma50, pma200])
[pma20w, pma50w, pma200w] = request.security(syminfo.tickerid, 'W', [pma20, pma50, pma200])
if barstate.islast and pmaStat and chart.is_standard
table.cell(change, 1, 3, '4H', text_color = naColor, bgcolor = color.new(naColor, 80), text_size = textSize)
table.cell(change, 2, 3, 'Day', text_color = naColor, bgcolor = color.new(naColor, 80), text_size = textSize)
table.cell(change, 3, 3, 'Week', text_color = naColor, bgcolor = color.new(naColor, 80), text_size = textSize)
table.cell(change, 0, 4, type_ma1 + ' ' + str.tostring(length_ma1), text_color = naColor, bgcolor = color.new(naColor, 80), text_halign = text.align_left, text_size = textSize)
table.cell(change, 1, 4, na(pma204h) ? '-' : str.tostring(pma204h, '#.##') + '%', text_color = na(pma204h) ? naColor : pma204h > 0 ? upColor2 : dnColor2, bgcolor = na(pma204h) ? color.new(naColor, 80) : pma204h > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize)
table.cell(change, 2, 4, na(pma20d) ? '-' : str.tostring(pma20d, '#.##') + '%', text_color = na(pma20d) ? naColor : pma20d > 0 ? upColor2 : dnColor2, bgcolor = na(pma20d) ? color.new(naColor, 80) : pma20d > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize)
table.cell(change, 3, 4, na(pma20w) ? '-' : str.tostring(pma20w, '#.##') + '%', text_color = na(pma20w) ? naColor : pma20w > 0 ? upColor2 : dnColor2, bgcolor = na(pma20w) ? color.new(naColor, 80) : pma20w > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize)
table.cell(change, 0, 5, type_ma2 + ' ' + str.tostring(length_ma2), text_color = naColor, bgcolor = color.new(naColor, 80), text_halign = text.align_left, text_size = textSize)
table.cell(change, 1, 5, na(pma504h) ? '-' : str.tostring(pma504h, '#.##') + '%', text_color = na(pma504h) ? naColor : pma504h > 0 ? upColor2 : dnColor2, bgcolor = na(pma504h) ? color.new(naColor, 80) : pma504h > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize)
table.cell(change, 2, 5, na(pma50d) ? '-' : str.tostring(pma50d, '#.##') + '%', text_color = na(pma50d) ? naColor : pma50d > 0 ? upColor2 : dnColor2, bgcolor = na(pma50d) ? color.new(naColor, 80) : pma50d > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize)
table.cell(change, 3, 5, na(pma50w) ? '-' : str.tostring(pma50w, '#.##') + '%', text_color = na(pma50w) ? naColor : pma50w > 0 ? upColor2 : dnColor2, bgcolor = na(pma50w) ? color.new(naColor, 80) : pma50w > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize)
table.cell(change, 0, 6, type_ma3 + ' ' + str.tostring(length_ma3), text_color = naColor, bgcolor = color.new(naColor, 80), text_halign = text.align_left, text_size = textSize)
table.cell(change, 1, 6, na(pma2004h) ? '-' : str.tostring(pma2004h, '#.##') + '%', text_color = na(pma2004h) ? naColor : pma2004h > 0 ? upColor2 : dnColor2, bgcolor = na(pma2004h) ? color.new(naColor, 80) : pma2004h > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize)
table.cell(change, 2, 6, na(pma200d) ? '-' : str.tostring(pma200d, '#.##') + '%', text_color = na(pma200d) ? naColor : pma200d > 0 ? upColor2 : dnColor2, bgcolor = na(pma200d) ? color.new(naColor, 80) : pma200d > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize)
table.cell(change, 3, 6, na(pma200w) ? '-' : str.tostring(pma200w, '#.##') + '%', text_color = na(pma200w) ? naColor : pma200w > 0 ? upColor2 : dnColor2, bgcolor = na(pma200w) ? color.new(naColor, 80) : pma200w > 0 ? color.new(upColor, 80) : color.new(dnColor, 80), text_size = textSize)
Show all 767 lines