Koncorde
//@version=4
//@andystoploss.com
study(title="Blai5 Koncorde", shorttitle="KONCORDE ASL")
calc_pvi() =>
    sval=volume
    pvi=(volume > volume[1]) ? nz(pvi[1]) + ((close - close[1])/close[1]) * (na(pvi[1]) ? pvi[1] : sval) : nz(pvi[1])
calc_nvi() =>
    sval=volume
    nvi=(volume < volume[1]) ? nz(nvi[1]) + ((close - close[1])/close[1]) * (na(nvi[1]) ? nvi[1] : sval) : nz(nvi[1])
calc_mfi(length) =>
    src=hlc3
    upper = sum(volume * (change(src) <= 0 ? 0 : src), length)
    lower = sum(volume * (change(src) >= 0 ? 0 : src), length)
    rsi(upper, lower)
tprice=ohlc4
lengthEMA = input(255, minval=1)
m=input(15)
//pvi = calc_pvi()
pvim = ema(pvi, m)
pvimax = highest(pvim, 90)
pvimin = lowest(pvim, 90)
oscp = (pvi - pvim) * 100/ (pvimax - pvimin)
//nvi =calc_nvi()
nvim = ema(nvi, m)
nvimax = highest(nvim, 90)
nvimin = lowest(nvim, 90)
azul = (nvi - nvim) * 100/ (nvimax - nvimin)
xmf = calc_mfi(14)
mult=input(2.0)
basis = sma(tprice, 25)
dev = mult * stdev(tprice, 25)
upper = basis + dev
lower = basis - dev
OB1 = (upper + lower) / 2.0
OB2 = upper - lower
BollOsc = ((tprice - OB1) / OB2 ) * 100
xrsi = rsi(tprice, 14)
calc_stoch(src, length,smoothFastD ) =>
    ll = lowest(low, length)
    hh = highest(high, length)
    k = 100 * (src - ll) / (hh - ll)
    sma(k, smoothFastD)
stoc = calc_stoch(tprice, 21, 3)
marron = (xrsi + xmf + BollOsc + (stoc / 3))/2
verde = marron + oscp
media = ema(marron,m)
plot(timeframe.isintraday ? 0 : verde, color=color.new(#25BC00,0), style=plot.style_columns, linewidth=4, title="verde")
plot(timeframe.isintraday ? 0 : marron, color=color.new(#FFC34C,0), style=plot.style_columns, linewidth=4, title="marron")
plot(timeframe.isintraday ? 0 : azul, color=color.new(#6C3AFF,0), style=plot.style_columns, linewidth=4, title="azul")
plot(marron, color=color.new(#000000,0), style=plot.style_line, linewidth=2, title="lmarron")
//plot(verde, color=#006600, style=plot.style_line, linewidth=2, title="lineav")
//plot(azul, color=#000066, style=plot.style_line, linewidth=2, title="lazul")
plot(media, color=color.new(#FF0000,0), title="media", style=plot.style_line, linewidth=2)
hline(0,color=color.black,linestyle=hline.style_solid)
// Picos Nevados y Mar
min_max = input(true, 'Show 3K Periods Min-Max?')
picos_nevados = marron
mar = marron
if min_max and barstate.islast
    for i = 0 to bar_index-20 < 0 ? 1 : bar_index > 3000 ? 3000 : bar_index-20  by 1
        picos_nevados := marron[i] > picos_nevados ? marron[i] : picos_nevados
        mar := marron[i] < mar ? marron[i] : mar
    var line picos_nevados_line = na
    var line mar_line = na
    picos_nevados_line := line.new(bar_index[1], picos_nevados, bar_index, picos_nevados, color=color.new(#000000,0), style=line.style_dotted, width=1, extend=extend.both)
    mar_line           := line.new(bar_index[1], mar, bar_index, mar, color=color.new(#000000,0), style=line.style_solid, width=1, extend=extend.both)