TA-Lib / ta-lib-python

Python wrapper for TA-Lib (http://ta-lib.org/).
http://ta-lib.github.io/ta-lib-python
Other
9.81k stars 1.78k forks source link

Blai5 Koncorde by manboto Python Tech Indicator market #573

Closed Leci37 closed 10 months ago

Leci37 commented 1 year ago

Blai5 Koncorde by manboto Python

https://es.tradingview.com/script/lLFiT3av/

Definition:

Koncorde is a mix of SIX indicators, 4 trend indicators and 2 volume indicators. Its representation is based on colored areas and not on simple lines, which (I believe) is also a certain novelty in the design of stock market indicators. The brown area and the red mean are trend and the green and blue areas are volume. For the calculation of the brown area (trend) an adjusted version of VIGIA is used, which is a weighted and amplified indicator composed of RSI, MFI, Bollinguer Bands and Stochastic. The green area and the blue area are obtained from the percentage change of the IVP (Positive Volume Index) and IVN (Negative Volume Index) indicators. Anyone reading the available documentation on these two little mathematical gems will discover that they ATTRIBUTE the volumes traded to either strong hands (IVN) or weak hands (IVP). In the case of Koncorde the strong hands are represented by the movements of the blue area and the weak hands by that of the green.

Example view:

KONKORDE_1 Feel free to improve and share, in case of error. Usage: https://github.com/Leci37/stocks-prediction-Machine-learning-RealTime-telegram/blob/develop/talib_technical_PY_TI.py

Python Code:

Pandas ta is requiered, look here https://pypi.org/project/pandas-ta/

import talib
# https://es.tradingview.com/script/lLFiT3av/
# Blai5 Koncorde by manboto copy
def get_konkorde_params(df_stocks):
    # df['calc_nvi'] =  df.ta.nvi( cumulative=True, append=False) #calc_nvi(df)
    # tprice=ohlc4
    tprice = (df_stocks['Open'] + df_stocks['High'] + df_stocks['Low'] + df_stocks['Close']) / 4
    # lengthEMA = input(255, minval=1)
    # pvi = calc_pvi()
    # df['calc_pvi'] = df.ta.pvi( cumulative=True, append=False) #calc_pvi(df)
    pvi = df_stocks.ta.nvi(cumulative=True, append=False)  # calc_pvi(df)
    m = 15
    # pvim = ema(pvi, m)
    pvim = talib.EMA(pvi, timeperiod=m)
    # pvimax = highest(pvim, 90)
    # pvimax = lowest(pvim, 90)
    pvimax = pvim.rolling(window=90).max()  # .shift(-89)
    pvimin = pvim.rolling(window=90).min()  # .shift(-89)
    # oscp = (pvi - pvim) * 100/ (pvimax - pvimin)
    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)
    nvi = df_stocks.ta.nvi(cumulative=True, append=False)  # calc_nvi(df)
    nvim = talib.EMA(nvi, timeperiod=15)
    nvimax = nvim.rolling(window=90).max()  # .shift(-89)
    nvimin = nvim.rolling(window=90).min()  # .shift(-89)
    val_blue = (nvi - nvim) * 100 / (nvimax - nvimin)
    xmf = talib.MFI(df_stocks['High'], df_stocks['Low'], df_stocks['Close'], df_stocks['Volume'], timeperiod=14)
    # mult=input(2.0)
    basis = talib.SMA(tprice, 25)
    dev = 2.0 * talib.STDDEV(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)
    OB1 = (upper + lower) / 2.0
    OB2 = upper - lower
    BollOsc = ((tprice - OB1) / OB2) * 100
    xrsi = talib.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)
    def calc_stoch(src, length, smoothFastD):
        ll = df_stocks['Low'].rolling(window=length).min()
        hh = df_stocks['High'].rolling(window=length).max()
        k = 100 * (src - ll) / (hh - ll)
        return talib.SMA(k, smoothFastD)

    stoc = calc_stoch(tprice, 21, 3)
    # stoc = py_ti.stochastic(tprice, 21, 3)
    val_brown = (xrsi + xmf + BollOsc + (stoc / 3)) / 2
    val_green = val_brown + oscp
    val_avg = talib.EMA(val_brown, timeperiod=m)
    return val_blue, val_brown, val_green,val_avg