Author message:
KONCORDE IS ONLY INTENDED TO BE APPLIED TO ASSETS WHERE VOLUME DATA IS PROVIDED.
This indicator is made up of 6 indicators: 4 trend ( RSI , MFI , BB, Stochastic ) and 2 volume . The 2's for volume are the PVI ( positive volume index ) and the NVI ( negative volume index ). These two indicators are the interesting ones as they are programmed to proportionally attribute the volume traded between the strong hands (sharks) and the weak hands (minnows).
As for what time period to use, the bigger the better, since after all what we are doing is data analysis and therefore the more data, the better.
When strong hands (blue histogram) are below zero, they are said to be selling while when they are above zero, they are said to be buying. The same goes for weak hands (green histogram).
Meaning of each zone:
Blue histogram: strong hand (sharks). If it is positive it indicates accumulation and if it is negative distribution.
Green histogram: weak hand (minnows). If it is positive it indicates buy and if it is negative it indicates sale.
Brown histogram: Indicates the trend and depends on previous values of weak hands and trend indicators ( RSI , MFI , BB, Stochastic ).
Red line: It is an average that smoothes the trend indicated by the brown histogram (default is the EMA ).
Crossing Pattern
The pattern gives us a bullish entry signal when the trend (brown histogram) crosses above the average (red line) and is positioned bearish when the trend crosses below the average.
Zero Pattern
When the price trend (brown histogram) tends to zero, it means that there will be a change in its trend. This pattern is for trading in a bullish position.
Spring Pattern
When a cross between the average (red line) and the trend (brown histogram) has already occurred, and in addition the weak hands are above the price trend, that "spring on the mountain" is formed that gives us to understand that the upward trend will be more than evident.
Mirror Pattern
This pattern occurs when there is panic in the market and weak hands are selling (below zero). If at that moment the strong hands are buyers, the price tends to level off to begin the rise later.
This pattern is compatible with the Crossover Pattern, having more guarantees of success. If just after finishing the mirror pattern, the Crossover Pattern plus the Spring Pattern appears, then we have a good chance of winning.
Bear Hug Pattern
This pattern is for bearish positions only. It is the opposite figure to the mirror pattern. That is, we have strong hands clearly selling and weak hands clearly buying and above the price trend (brown histogram). It is the figure where you can see that the strong hands are distributing the assets to the weak hands.
Harpoon Pattern
If when the mirror pattern occurs, the red line crosses the blue histogram, a very strong bullish entry signal is produced.
Add an exit signal which occurs when we are in a spring pattern but the big hands start selling, mostly coinciding with the start of the bear hug pattern.
General rules for operating the Mirror Pattern:
a) Wait for the green histogram to start recovery, rise to positive values; if possible, until it crosses from bottom to top the brown line (brown histogram) and/or red average .
b) The blue histogram should be consistently positive. If it turns and goes towards negative values it can indicate a failed pattern at that same point.
c) Locate the low of the lower candle within the pattern and place the Stop Loss just below it for reference.
d) If we are not sure (we almost never will be) that there will be a turn or if it could finally be a bearish continuation we can use the SL to go short .
Additional:
A panel with performance statistics of the analyzed asset was added.
CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0
#https://www.tradingview.com/script/mAEzn9Im-Koncorde-Plus/
#// © OskarGallard
#indicator("Koncorde Plus", "Koncorde [+]")
# Converted by Sam4Cok@Samer800 - 10/2022 - not typical
declare lower;
input timeOfPhaseProfile = {Default Day, Week, Month, Quarter, Year};
def na = Double.NaN;
def h = high;
def c = close;
def l = low;
def o = open;
def v = volume;
script nz {
input data = close;
input repl = 0;
def ret_val = if isNaN(data) then repl else data;
plot return = ret_val;
}
#f_htf_ohlc(_htf) =>
script f_htf_ohlc {
input _htf = AggregationPeriod.DAY;
def time = close(period = _htf);
def htf_cx;
if (time != time[1]) {
htf_cx = time[1];
} else {
htf_cx = htf_cx[1];
}
plot cx = htf_cx;
}
input MirrorPattern = yes; # "Mirror Pattern"
input BearHugPattern = no; # "Bear Hug Pattern"
input CrossingPattern = no; # "Crossing Pattern"
input SpringPattern = no; # "Spring Pattern"
input ZeroPattern = yes; # "Zero Pattern"
input HarpoonPattern = yes; # "Harpoon Pattern",
input Label = yes; # "Statistic Panel of Performance (Change)"
input TrendSrc = ohlc4; # "RSI, BB & Stoch Source"
input srcMfi = hlc3; # "MFI Source"
input len_mfi_rsi = 14; # "MFI & RSI Length"
input length_bb = 25; # "BB Length"
input mult_bb = 2.0; # "BB Multiplier"
input length_ma = 15; # "MA Length"
input type_ma = {"SMA",Default "EMA", "Wilder", "WMA", "VWMA", "ALMA", "LSMA", "HMA", "VAMA", "JMA"};
#// Volume Type
input voltype = {Default "Default", "Tick"};
#// ALMA Offset and Sigma
input almaOffset = 0.85; # "Offset (if ALMA)"
input sigma = 6; # "Sigma (if ALMA)"
#// JMA
input phaseJ = 50; # "Phase (if JMA)"
input powerJ = 2; # "Power (if JMA)"
#// LSMA Offset
input loff = 0; # "Offset (if LSMA)"
input m_pvi_nvi = 15; # "PVI & NVI Length"
input longitudPVI = 90; # "Min-Max Period [PVI]"
input longitudNVI = 90; # "Min-Max Period [NVI]"
input show_delta = no; # "Show Volume Delta Line"
input fast_len = 5; # "Fast MA"
input type_fast = {"SMA", "EMA",Default "Wilder", "WMA", "ALMA", "LSMA", "HMA", "JMA"};
input slow_len = 21; # "Slow MA"
input type_slow = {"SMA",Default "EMA", "Wilder", "WMA", "ALMA", "LSMA", "HMA", "JMA"};
#jma(src, length, power, phase) =>
script jma {
input src = hlc3;
input length = 10;
input power = 0;
input phase = 0;
def phaseRatio = if phase < -100 then 0.5 else
if phase > 100 then 2.5 else phase / 100 + 1.5;
def beta = 0.45 * (length - 1) / (0.45 * (length - 1) + 2);
def alpha = power(beta, power);
def Jma;
def e0;
def e1;
def e2;
e0 = (1 - alpha) * src + alpha * nz(e0[1]);
e1 = (src - e0) * (1 - beta) + beta * nz(e1[1]);
e2 = (e0 + phaseRatio * e1 - nz(Jma[1])) * power(1 - alpha, 2) + power(alpha, 2) * nz(e2[1]);
Jma = e2 + nz(Jma[1]);
plot return = Jma;
}
#enhanced_alma(_series, _length, _offset, _sigma) =>
script enhanced_alma {
input _series = close;
input _length = 10;
input _offset = 0;
input _sigma = 0;
def length = _length;
def numerator;
def denominator;
def m = _offset * (length - 1);
def s = length / _sigma;
numerator = fold i=0 to length-1 with p do
numerator[1] + (exp(-((i-m)*(i-m)) / (2 * s * s))) * GetValue(_series,length - 1 - i);
denominator = fold j=0 to length-1 with q do
denominator[1] + (exp(-((j-m)*(j-m)) / (2 * s * s)));
def alma = numerator / denominator;
plot return = alma;
}
#// Tick Volume
def tick = TickValue();
def rng = c - o;
def tickrng = if isNaN(tickrng[1]) then tick else
if AbsValue(rng) < tick then nz(tickrng[1]) else rng;
def tickvol = AbsValue(tickrng)/tick;
def volumen = if nz(v) == 0 then tickvol else v;
#enhanced_vwma(_series, _length, voltype) =>
script enhanced_vwma {
input _series = close;
input _length = 10;
input voltype = "Default";
def tick = TickValue();
def rng = close - open;
def tickrng = if isNaN(tickrng[1]) then tick else
if AbsValue(rng) < tick then nz(tickrng[1]) else rng;
def tickvol = AbsValue(tickrng)/tick;
def volumen = if nz(volume) == 0 then tickvol else volume;
def vol = if voltype == "Default" then tickvol else volumen;
def vmp = _series * vol;
def VWMA = sum(vmp, _length) / sum(vol, _length);
plot return = VWMA;
}
#ma(_type, _source, _length, voltype, offs,sigma, powerJ, phaseJ, loff ) =>
script ma{
input _type = "SMA";
input _source = hlc3;
input _length = 14;
input voltype = 0;
input offs = 0.85;
input sigma = 6;
input powerJ = 2;
input phaseJ = 50;
input loff = 0;
def ma =
if _type == "SMA" then SimpleMovingAvg(_source, _length) else
if _type == "EMA" then ExpAverage(_source, _length) else
if _type == "WMA" then wma(_source, _length) else
if _type == "VWMA" then enhanced_vwma(_source, _length, voltype) else
if _type == "LSMA" then inertia(_source[-loff], _length) else
if _type == "ALMA" then enhanced_alma(_source, _length, offs, sigma) else
if _type == "HMA" then HullMovingAvg(_source, _length)else
if _type == "VAMA" then VariableMA(_source, _length)else
if _type == "JMA" then jma(_source, _length, powerJ, phaseJ) else
if _type == "Wilder" then WildersAverage(_source, _length) else double.NaN;
plot return = ma;
}
#pine_mfi(src, length) =>
script mfi {
input src = hlc3;
input length = 14;
def v = volume;
def upper = sum(v * (if (src-src[1]) <= 0.0 then 0.0 else src), length);
def lower = sum(v * (if (src-src[1]) >= 0.0 then 0.0 else src), length);
def mfi = 100.0 - (100.0 / (1.0 + upper / lower));
plot return = mfi;
}
#f_bb(source, length, mult_bb) =>
script f_bb {
input source= hlc3;
input length = 20;
input mult_bb = 2;
def basis = SimpleMovingAvg(source, length);
def dev = mult_bb * stdev(source, length);
def upper = basis + dev; # // Upper Band
def lower = basis - dev; # // Lower Band
def avg_up_low = (upper + lower) / 2;
def diff_up_low = upper - lower;
def f_bb =(source - avg_up_low) / diff_up_low * 100;
plot return = f_bb;
}
def ll = lowest(l, 21);
def hh = highest(h, 21);
def k = 100 * (TrendSrc - ll) / (hh - ll);
def f_stoc = SimpleMovingAvg(k, 3);
#-----
def pvi;
def prevPvi = if nz(pvi[1]) == 0 then 1 else pvi[1];
if c == 0 or c[1] == 0 {
pvi = prevPvi;
} else {
pvi = if (v > nz(v[1], 0.0)) then
prevPvi + ((c - c[1]) / c[1]) * prevPvi else prevPvi;}
def nvi;
def prevNvi = if(nz(nvi[1], 0.0) == 0.0) then 1.0 else nvi[1];
if c == 0 or c[1] == 0 {
nvi = prevNvi;
} else {
nvi = if (v < nz(v[1], 0.0)) then
prevNvi + ((c - c[1]) / c[1]) * prevNvi else prevNvi;}
def pvi_media = ExpAverage(pvi, m_pvi_nvi);
def pvi_max = highest(pvi_media, longitudPVI);
def pvi_min = lowest(pvi_media, longitudPVI);
def osc_pos = (pvi - pvi_media)*100 / (pvi_max - pvi_min);
def nvi_media = ExpAverage(nvi, m_pvi_nvi);
def nvi_max = highest(nvi_media, longitudNVI);
def nvi_min = lowest(nvi_media, longitudNVI);
def osc_neg = (nvi - nvi_media)*100 / (nvi_max - nvi_min);
#----------------------------
def rsi_valor = rsi(Price = TrendSrc, Length = len_mfi_rsi);
def mfi_valor = mfi(srcMfi, len_mfi_rsi);
def osc_bb = f_bb(TrendSrc,length_bb, mult_bb);
def stoc = f_stoc;
def tendencia = (rsi_valor + mfi_valor + osc_bb + stoc/3) / 2;
def tiburones = SimpleMovingAvg(osc_neg, 1);
def pececillos = tendencia + osc_pos;
def ma_trend = ma(type_ma, tendencia, length_ma,voltype, almaOffset,sigma, powerJ, phaseJ, loff);
def patron_espejo = (pececillos < 0 and tiburones > 0);
def patron_oso = (pececillos > 0 and tiburones < 0) and pececillos >= tendencia;
def patron_cero = (tendencia crosses above 0);
def cross_up_trend = (tendencia crosses above ma_trend);
def cross_dn_trend = (tendencia crosses below ma_trend);
def patron_primavera = ((tendencia crosses above ma_trend) and pececillos > tendencia);
def cross_up_shark = (tiburones crosses above ma_trend) and (pececillos < 0 and tiburones > 0);
def cross_dn_shark = (tiburones crosses below 0) and pececillos > tendencia;
plot MaTrend = ma_trend; # "MA of Trend"
MaTrend.SetDefaultColor(CreateColor(255,0,0));
MaTrend.SetLineWeight(2);
plot Trend = tendencia; # "Trend"
Trend.AssignValueColor(if tendencia > tendencia[1] then CreateColor(141,73,37) else CreateColor(50,0,0));
plot Shark = tiburones; # "Shark"
Shark.SetLineWeight(2);
Shark.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Shark.AssignValueColor( if tiburones > 0 then CreateColor(0,176,246) else CreateColor(0,55,133));
plot Minnows = pececillos; # "Minnows"
Minnows.SetLineWeight(2);
Minnows.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Minnows.AssignValueColor( if pececillos > 0 then CreateColor(5,255,104) else CreateColor(0,153,41));
plot Trend1 = tendencia; # "Trend"
Trend1.SetLineWeight(2);
Trend1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Trend1.AssignValueColor(if tendencia > tendencia[1] then CreateColor(141,73,37) else CreateColor(50,0,0));
plot Crossover = if CrossingPattern then if cross_up_trend then -80 else na else na;
Crossover.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Crossover.SetDefaultColor(CreateColor(0,128,128));
plot Crossunder = if CrossingPattern then if cross_dn_trend then 80 else na else na;
Crossunder.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Crossunder.SetDefaultColor(Color.RED);
plot Zero_Pattern = if ZeroPattern then if patron_cero then -80 else na else na;
Zero_Pattern.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Zero_Pattern.SetDefaultColor(CreateColor(255,204,153));
plot Spring_Pattern = if SpringPattern then if patron_primavera then -80 else na else na;
Spring_Pattern.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Spring_Pattern.SetDefaultColor(Color.GREEN);
plot Harpoon_Pattern = if HarpoonPattern then if cross_up_shark then -80 else na else na;
Harpoon_Pattern.SetPaintingStrategy(PaintingStrategy.SQUARES);
Harpoon_Pattern.SetDefaultColor(Color.CYAN);
plot ExitHarpPat = if HarpoonPattern then if cross_dn_shark then MaTrend else na else na;
ExitHarpPat.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ExitHarpPat.SetDefaultColor(Color.RED);
AddCloud(if MirrorPattern and patron_espejo then Double.POSITIVE_INFINITY else na, Double.NEGATIVE_INFINITY, Color.CYAN); # "Mirror Pattern"
AddCloud(if BearHugPattern and patron_oso then Double.POSITIVE_INFINITY else na,Double.NEGATIVE_INFINITY,Color.DARK_RED); # "Bear Hug Pattern
#// Delta Arrows
#f_rate(cond) =>
script f_rate {
input cond = yes;
def o = open; def c = close; def l = low; def h = high;
def tw = h - max(o, c);
def bw = min(o, c) - l;
def body = AbsValue(c - o);
def ret = 0.5 * (tw + bw + (if cond then 2 * body else 0)) / (tw + bw + body);
def ret1 = if nz(ret) == 0 then 0.5 else ret;
plot return = ret1;
}
def delta_up = v * f_rate(o <= c);
def delta_down = v * f_rate(o > c);
def delta = if c >= o then delta_up else -delta_down;
def cum_delta = TotalSum(delta);
def ma_fast = ma(type_fast, cum_delta, fast_len) ;
def ma_slow = ma(type_slow, cum_delta, slow_len) ;
def delta_osc = ma_fast - ma_slow;
def sc1 = delta_osc >= 0;
def sc2 = delta_osc < 0;
def sc3 = delta_osc >= delta_osc[1];
def sc4 = delta_osc < delta_osc[1];
def col_delta_up = if sc1 and sc3 then 1 else #8080FF
if sc1 and sc4 then -1 else 0; #40407F : color.silver
def col_delta_dn = if sc2 and sc4 then 1 else #FF8080
if sc2 and sc3 then -1 else 0; #7F4040 : color.silver
plot UpDelta = if show_delta and delta_osc >= 0 then 150 else na; #"Up Delta"
UpDelta.SetPaintingStrategy(PAintingStrategy.POINTS);
upDelta.AssignValueColor(if col_delta_up > 0 then CreateColor(128,128,255) else
if col_delta_up < 0 then CreateColor(64,64,127) else Color.GRAY);
plot DownDelta = if show_delta and delta_osc < 0 then 150 else na; #"Down Delta"
DownDelta.SetPaintingStrategy(PAintingStrategy.POINTS);
DownDelta.AssignValueColor(if col_delta_dn > 0 then CreateColor(255,128,128) else
if col_delta_up < 0 then CreateColor(127,64,64) else Color.GRAY);
#// Performance Table
def Cd = f_htf_ohlc(timeOfPhaseProfile);
def Perform = ROUND((c / Cd - 1) * 100,2);
addlabel(Label,timeOfPhaseProfile +"(" + Perform +"%)",if Perform > 0 then color.GREEN else color.RED);
#____
#// Inputs
input show_DVDI = no;#"????? Show Dual Volume Divergence Index ?????")
#// Tick Volume Toggle
input usetick = no;#(false, "Use Tick Volume", inline="extra2")
input show_bar_dvdi = no;#(false, "Show Bars Color", inline="extra2")
#// Source
input src = close;#, "Source")
#// Sampling Period
input per = 55;#, "Sampling Period", 1)
input SmoothingPeriod = 1;#(1, "Smoothing Period", 1)
#
#// Dual Volume Divergence Index
#dvdi(x, t1, t2, v)=>
script dvdi {
input x = close;
input t1 = 0;
input t2 = 0;
input v = volume;
def ROC_x = if x[1] != 0 then (x-x[1]) / x[1] * 100 else 0;
# def roc_x = RateOfChange(Price = x, Length = 1);
def pvi;
pvi = if isNaN(pvi[1]) then x else
if v > v[1] then nz(pvi[1]) + roc_x else nz(pvi[1]);
def psig = ExpAverage(pvi, t1);
def PDIV1 = ExpAverage(pvi - psig, t2);
def nvi;
nvi = if isNaN(nvi[1]) then x else
if v < v[1] then nz(nvi[1]) - roc_x else nz(nvi[1]);
def nsig = ExpAverage(nvi, t1);
def NDIV1 = ExpAverage(nvi - nsig, t2);
plot pdiv = PDIV1;
plot ndiv = NDIV1;
}
def vol = if usetick then tickvol else v;
def pdiv = dvdi(src, per, SmoothingPeriod, vol).pdiv;
def ndiv = dvdi(src, per, SmoothingPeriod, vol).ndiv;
#// Dual Index Plots
plot pplot = if show_DVDI then pdiv else na;#, "PVI Divergence", #05FFA6)
pplot.SetDefaultColor(Color.GREEN);
plot nplot = if show_DVDI then ndiv else na;#, "NVI Divergence", #FF0A70)
nplot.SetDefaultColor(Color.RED);
#// Bar Colors
Def Barcolor = if (pdiv > ndiv) and (pdiv > 0) then 1 else #05ffa6
if (pdiv > ndiv) and (pdiv <= 0) then 2 else #00945f
if (ndiv > pdiv) and (ndiv > 0)then -1 else #ff0a70
if (ndiv > pdiv) and (ndiv <= 0) then -2 else 0;#990040: #cccccc
AssignPriceColor(if show_bar_dvdi then
if Barcolor == 1 then CreateColor(5,255,166) else
if Barcolor == 2 then CreateColor(0,148,95) else
if Barcolor == -1 then CreateColor(255,10,112) else
if Barcolor == -2 then CreateColor(153,0,64) else Color.GRAY else Color.CURRENT);
### END
Added option to show hist or area
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0
#https://www.tradingview.com/script/mAEzn9Im-Koncorde-Plus/
#// © OskarGallard
#indicator("Koncorde Plus", "Koncorde [+]")
# Converted by Sam4Cok@Samer800 - 10/2022 - not typical
# added option to show the plot as histogram or area
declare lower;
input timeOfPhaseProfile = {Default Day, Week, Month, Quarter, Year};
def na = Double.NaN;
def h = high;
def c = close;
def l = low;
def o = open;
def v = volume;
script nz {
input data = close;
input repl = 0;
def ret_val = if isNaN(data) then repl else data;
plot return = ret_val;
}
#f_htf_ohlc(_htf) =>
script f_htf_ohlc {
input _htf = AggregationPeriod.DAY;
def time = close(period = _htf);
def htf_cx;
if (time != time[1]) {
htf_cx = time[1];
} else {
htf_cx = htf_cx[1];
}
plot cx = htf_cx;
}
input ShowHist = yes;
input MirrorPattern = yes; # "Mirror Pattern"
input BearHugPattern = no; # "Bear Hug Pattern"
input CrossingPattern = no; # "Crossing Pattern"
input SpringPattern = no; # "Spring Pattern"
input ZeroPattern = yes; # "Zero Pattern"
input HarpoonPattern = yes; # "Harpoon Pattern",
input Label = yes; # "Statistic Panel of Performance (Change)"
input TrendSrc = ohlc4; # "RSI, BB & Stoch Source"
input srcMfi = hlc3; # "MFI Source"
input len_mfi_rsi = 14; # "MFI & RSI Length"
input length_bb = 25; # "BB Length"
input mult_bb = 2.0; # "BB Multiplier"
input length_ma = 15; # "MA Length"
input type_ma = {"SMA",Default "EMA", "Wilder", "WMA", "VWMA", "ALMA", "LSMA", "HMA", "VAMA", "JMA"};
#// Volume Type
input voltype = {Default "Default", "Tick"};
#// ALMA Offset and Sigma
input almaOffset = 0.85; # "Offset (if ALMA)"
input sigma = 6; # "Sigma (if ALMA)"
#// JMA
input phaseJ = 50; # "Phase (if JMA)"
input powerJ = 2; # "Power (if JMA)"
#// LSMA Offset
input loff = 0; # "Offset (if LSMA)"
input m_pvi_nvi = 15; # "PVI & NVI Length"
input longitudPVI = 90; # "Min-Max Period [PVI]"
input longitudNVI = 90; # "Min-Max Period [NVI]"
input show_delta = no; # "Show Volume Delta Line"
input fast_len = 5; # "Fast MA"
input type_fast = {"SMA", "EMA",Default "Wilder", "WMA", "ALMA", "LSMA", "HMA", "JMA"};
input slow_len = 21; # "Slow MA"
input type_slow = {"SMA",Default "EMA", "Wilder", "WMA", "ALMA", "LSMA", "HMA", "JMA"};
#jma(src, length, power, phase) =>
script jma {
input src = hlc3;
input length = 10;
input power = 0;
input phase = 0;
def phaseRatio = if phase < -100 then 0.5 else
if phase > 100 then 2.5 else phase / 100 + 1.5;
def beta = 0.45 * (length - 1) / (0.45 * (length - 1) + 2);
def alpha = power(beta, power);
def Jma;
def e0;
def e1;
def e2;
e0 = (1 - alpha) * src + alpha * nz(e0[1]);
e1 = (src - e0) * (1 - beta) + beta * nz(e1[1]);
e2 = (e0 + phaseRatio * e1 - nz(Jma[1])) * power(1 - alpha, 2) + power(alpha, 2) * nz(e2[1]);
Jma = e2 + nz(Jma[1]);
plot return = Jma;
}
#enhanced_alma(_series, _length, _offset, _sigma) =>
script enhanced_alma {
input _series = close;
input _length = 10;
input _offset = 0;
input _sigma = 0;
def length = _length;
def numerator;
def denominator;
def m = _offset * (length - 1);
def s = length / _sigma;
numerator = fold i=0 to length-1 with p do
numerator[1] + (exp(-((i-m)*(i-m)) / (2 * s * s))) * GetValue(_series,length - 1 - i);
denominator = fold j=0 to length-1 with q do
denominator[1] + (exp(-((j-m)*(j-m)) / (2 * s * s)));
def alma = numerator / denominator;
plot return = alma;
}
#// Tick Volume
def tick = TickValue();
def rng = c - o;
def tickrng = if isNaN(tickrng[1]) then tick else
if AbsValue(rng) < tick then nz(tickrng[1]) else rng;
def tickvol = AbsValue(tickrng)/tick;
def volumen = if nz(v) == 0 then tickvol else v;
#enhanced_vwma(_series, _length, voltype) =>
script enhanced_vwma {
input _series = close;
input _length = 10;
input voltype = "Default";
def tick = TickValue();
def rng = close - open;
def tickrng = if isNaN(tickrng[1]) then tick else
if AbsValue(rng) < tick then nz(tickrng[1]) else rng;
def tickvol = AbsValue(tickrng)/tick;
def volumen = if nz(volume) == 0 then tickvol else volume;
def vol = if voltype == "Default" then tickvol else volumen;
def vmp = _series * vol;
def VWMA = sum(vmp, _length) / sum(vol, _length);
plot return = VWMA;
}
#ma(_type, _source, _length, voltype, offs,sigma, powerJ, phaseJ, loff ) =>
script ma{
input _type = "SMA";
input _source = hlc3;
input _length = 14;
input voltype = 0;
input offs = 0.85;
input sigma = 6;
input powerJ = 2;
input phaseJ = 50;
input loff = 0;
def ma =
if _type == "SMA" then SimpleMovingAvg(_source, _length) else
if _type == "EMA" then ExpAverage(_source, _length) else
if _type == "WMA" then wma(_source, _length) else
if _type == "VWMA" then enhanced_vwma(_source, _length, voltype) else
if _type == "LSMA" then inertia(_source[-loff], _length) else
if _type == "ALMA" then enhanced_alma(_source, _length, offs, sigma) else
if _type == "HMA" then HullMovingAvg(_source, _length)else
if _type == "VAMA" then VariableMA(_source, _length)else
if _type == "JMA" then jma(_source, _length, powerJ, phaseJ) else
if _type == "Wilder" then WildersAverage(_source, _length) else double.NaN;
plot return = ma;
}
#pine_mfi(src, length) =>
script mfi {
input src = hlc3;
input length = 14;
def v = volume;
def upper = sum(v * (if (src-src[1]) <= 0.0 then 0.0 else src), length);
def lower = sum(v * (if (src-src[1]) >= 0.0 then 0.0 else src), length);
def mfi = 100.0 - (100.0 / (1.0 + upper / lower));
plot return = mfi;
}
#f_bb(source, length, mult_bb) =>
script f_bb {
input source= hlc3;
input length = 20;
input mult_bb = 2;
def basis = SimpleMovingAvg(source, length);
def dev = mult_bb * stdev(source, length);
def upper = basis + dev; # // Upper Band
def lower = basis - dev; # // Lower Band
def avg_up_low = (upper + lower) / 2;
def diff_up_low = upper - lower;
def f_bb =(source - avg_up_low) / diff_up_low * 100;
plot return = f_bb;
}
def ll = lowest(l, 21);
def hh = highest(h, 21);
def k = 100 * (TrendSrc - ll) / (hh - ll);
def f_stoc = SimpleMovingAvg(k, 3);
#-----
def pvi;
def prevPvi = if nz(pvi[1]) == 0 then 1 else pvi[1];
if c == 0 or c[1] == 0 {
pvi = prevPvi;
} else {
pvi = if (v > nz(v[1], 0.0)) then
prevPvi + ((c - c[1]) / c[1]) * prevPvi else prevPvi;}
def nvi;
def prevNvi = if(nz(nvi[1], 0.0) == 0.0) then 1.0 else nvi[1];
if c == 0 or c[1] == 0 {
nvi = prevNvi;
} else {
nvi = if (v < nz(v[1], 0.0)) then
prevNvi + ((c - c[1]) / c[1]) * prevNvi else prevNvi;}
def pvi_media = ExpAverage(pvi, m_pvi_nvi);
def pvi_max = highest(pvi_media, longitudPVI);
def pvi_min = lowest(pvi_media, longitudPVI);
def osc_pos = (pvi - pvi_media)*100 / (pvi_max - pvi_min);
def nvi_media = ExpAverage(nvi, m_pvi_nvi);
def nvi_max = highest(nvi_media, longitudNVI);
def nvi_min = lowest(nvi_media, longitudNVI);
def osc_neg = (nvi - nvi_media)*100 / (nvi_max - nvi_min);
#----------------------------
def rsi_valor = rsi(Price = TrendSrc, Length = len_mfi_rsi);
def mfi_valor = mfi(srcMfi, len_mfi_rsi);
def osc_bb = f_bb(TrendSrc,length_bb, mult_bb);
def stoc = f_stoc;
def tendencia = (rsi_valor + mfi_valor + osc_bb + stoc/3) / 2;
def tiburones = SimpleMovingAvg(osc_neg, 1);
def pececillos = tendencia + osc_pos;
def ma_trend = ma(type_ma, tendencia, length_ma,voltype, almaOffset,sigma, powerJ, phaseJ, loff);
def patron_espejo = (pececillos < 0 and tiburones > 0);
def patron_oso = (pececillos > 0 and tiburones < 0) and pececillos >= tendencia;
def patron_cero = (tendencia crosses above 0);
def cross_up_trend = (tendencia crosses above ma_trend);
def cross_dn_trend = (tendencia crosses below ma_trend);
def patron_primavera = ((tendencia crosses above ma_trend) and pececillos > tendencia);
def cross_up_shark = (tiburones crosses above ma_trend) and (pececillos < 0 and tiburones > 0);
def cross_dn_shark = (tiburones crosses below 0) and pececillos > tendencia;
plot MaTrend = ma_trend; # "MA of Trend"
MaTrend.SetDefaultColor(CreateColor(255,0,0));
MaTrend.SetLineWeight(2);
plot Trend = tendencia; # "Trend"
Trend.AssignValueColor(if tendencia > tendencia[1] then CreateColor(141,73,37) else CreateColor(50,0,0));
plot Shark = tiburones; # "Shark"
#Shark.SetLineWeight(1);
Shark.SetPaintingStrategy(if ShowHist then PaintingStrategy.SQUARED_HISTOGRAM else PaintingStrategy.LINE);
Shark.AssignValueColor( if tiburones > 0 then CreateColor(0,176,246) else CreateColor(0,55,133));
plot Minnows = pececillos; # "Minnows"
#Minnows.SetLineWeight(1);
Minnows.SetPaintingStrategy(if ShowHist then PaintingStrategy.SQUARED_HISTOGRAM else PaintingStrategy.LINE);
Minnows.AssignValueColor( if pececillos > 0 then CreateColor(5,255,104) else CreateColor(0,153,41));
plot Trend1 = tendencia; # "Trend"
#Trend1.SetLineWeight(1);
Trend1.SetPaintingStrategy(if ShowHist then PaintingStrategy.SQUARED_HISTOGRAM else PaintingStrategy.LINE);
Trend1.AssignValueColor(if tendencia > tendencia[1] then CreateColor(141,73,37) else CreateColor(50,0,0));
#--------------------------
AddCloud(Minnows,0,CreateColor(76,175,80),CreateColor(76,175,80));
AddCloud(Trend1, 0,CreateColor(255,204,153),CreateColor(255,204,153));
AddCloud(Shark, 0 ,CreateColor(0,216,212),CreateColor(0,216,212));
#---------------------------
plot Crossover = if CrossingPattern then if cross_up_trend then -80 else na else na;
Crossover.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Crossover.SetDefaultColor(CreateColor(0,128,128));
plot Crossunder = if CrossingPattern then if cross_dn_trend then 80 else na else na;
Crossunder.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Crossunder.SetDefaultColor(Color.RED);
plot Zero_Pattern = if ZeroPattern then if patron_cero then -80 else na else na;
Zero_Pattern.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Zero_Pattern.SetDefaultColor(CreateColor(255,204,153));
plot Spring_Pattern = if SpringPattern then if patron_primavera then -80 else na else na;
Spring_Pattern.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Spring_Pattern.SetDefaultColor(Color.GREEN);
plot Harpoon_Pattern = if HarpoonPattern then if cross_up_shark then -80 else na else na;
Harpoon_Pattern.SetPaintingStrategy(PaintingStrategy.SQUARES);
Harpoon_Pattern.SetDefaultColor(Color.CYAN);
plot ExitHarpPat = if HarpoonPattern then if cross_dn_shark then MaTrend else na else na;
ExitHarpPat.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ExitHarpPat.SetDefaultColor(Color.RED);
AddCloud(if MirrorPattern and patron_espejo then Double.POSITIVE_INFINITY else na, Double.NEGATIVE_INFINITY, Color.CYAN); # "Mirror Pattern"
AddCloud(if BearHugPattern and patron_oso then Double.POSITIVE_INFINITY else na,Double.NEGATIVE_INFINITY,Color.DARK_RED); # "Bear Hug Pattern
#// Delta Arrows
#f_rate(cond) =>
script f_rate {
input cond = yes;
def o = open; def c = close; def l = low; def h = high;
def tw = h - max(o, c);
def bw = min(o, c) - l;
def body = AbsValue(c - o);
def ret = 0.5 * (tw + bw + (if cond then 2 * body else 0)) / (tw + bw + body);
def ret1 = if nz(ret) == 0 then 0.5 else ret;
plot return = ret1;
}
def delta_up = v * f_rate(o <= c);
def delta_down = v * f_rate(o > c);
def delta = if c >= o then delta_up else -delta_down;
def cum_delta = TotalSum(delta);
def ma_fast = ma(type_fast, cum_delta, fast_len) ;
def ma_slow = ma(type_slow, cum_delta, slow_len) ;
def delta_osc = ma_fast - ma_slow;
def sc1 = delta_osc >= 0;
def sc2 = delta_osc < 0;
def sc3 = delta_osc >= delta_osc[1];
def sc4 = delta_osc < delta_osc[1];
def col_delta_up = if sc1 and sc3 then 1 else #8080FF
if sc1 and sc4 then -1 else 0; #40407F : color.silver
def col_delta_dn = if sc2 and sc4 then 1 else #FF8080
if sc2 and sc3 then -1 else 0; #7F4040 : color.silver
plot UpDelta = if show_delta and delta_osc >= 0 then 150 else na; #"Up Delta"
UpDelta.SetPaintingStrategy(PAintingStrategy.POINTS);
upDelta.AssignValueColor(if col_delta_up > 0 then CreateColor(128,128,255) else
if col_delta_up < 0 then CreateColor(64,64,127) else Color.GRAY);
plot DownDelta = if show_delta and delta_osc < 0 then 150 else na; #"Down Delta"
DownDelta.SetPaintingStrategy(PAintingStrategy.POINTS);
DownDelta.AssignValueColor(if col_delta_dn > 0 then CreateColor(255,128,128) else
if col_delta_up < 0 then CreateColor(127,64,64) else Color.GRAY);
#// Performance Table
def Cd = f_htf_ohlc(timeOfPhaseProfile);
def Perform = ROUND((c / Cd - 1) * 100,2);
addlabel(Label,timeOfPhaseProfile +"(" + Perform +"%)",if Perform > 0 then color.GREEN else color.RED);
#____
#// Inputs
input show_DVDI = no;#"????? Show Dual Volume Divergence Index ?????")
#// Tick Volume Toggle
input usetick = no;#(false, "Use Tick Volume", inline="extra2")
input show_bar_dvdi = no;#(false, "Show Bars Color", inline="extra2")
#// Source
input src = close;#, "Source")
#// Sampling Period
input per = 55;#, "Sampling Period", 1)
input SmoothingPeriod = 1;#(1, "Smoothing Period", 1)
#
#// Dual Volume Divergence Index
#dvdi(x, t1, t2, v)=>
script dvdi {
input x = close;
input t1 = 0;
input t2 = 0;
input v = volume;
def ROC_x = if x[1] != 0 then (x-x[1]) / x[1] * 100 else 0;
# def roc_x = RateOfChange(Price = x, Length = 1);
def pvi;
pvi = if isNaN(pvi[1]) then x else
if v > v[1] then nz(pvi[1]) + roc_x else nz(pvi[1]);
def psig = ExpAverage(pvi, t1);
def PDIV1 = ExpAverage(pvi - psig, t2);
def nvi;
nvi = if isNaN(nvi[1]) then x else
if v < v[1] then nz(nvi[1]) - roc_x else nz(nvi[1]);
def nsig = ExpAverage(nvi, t1);
def NDIV1 = ExpAverage(nvi - nsig, t2);
plot pdiv = PDIV1;
plot ndiv = NDIV1;
}
def vol = if usetick then tickvol else v;
def pdiv = dvdi(src, per, SmoothingPeriod, vol).pdiv;
def ndiv = dvdi(src, per, SmoothingPeriod, vol).ndiv;
#// Dual Index Plots
plot pplot = if show_DVDI then pdiv else na;#, "PVI Divergence", #05FFA6)
pplot.SetDefaultColor(Color.GREEN);
plot nplot = if show_DVDI then ndiv else na;#, "NVI Divergence", #FF0A70)
nplot.SetDefaultColor(Color.RED);
#// Bar Colors
Def Barcolor = if (pdiv > ndiv) and (pdiv > 0) then 1 else #05ffa6
if (pdiv > ndiv) and (pdiv <= 0) then 2 else #00945f
if (ndiv > pdiv) and (ndiv > 0)then -1 else #ff0a70
if (ndiv > pdiv) and (ndiv <= 0) then -2 else 0;#990040: #cccccc
AssignPriceColor(if show_bar_dvdi then
if Barcolor == 1 then CreateColor(5,255,166) else
if Barcolor == 2 then CreateColor(0,148,95) else
if Barcolor == -1 then CreateColor(255,10,112) else
if Barcolor == -2 then CreateColor(153,0,64) else Color.GRAY else Color.CURRENT);
### END
Last edited by a moderator: