Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #// 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 = no;
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement