Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Koncorde by manboto Python #633

Open
Leci37 opened this issue Jan 7, 2023 · 3 comments
Open

Koncorde by manboto Python #633

Leci37 opened this issue Jan 7, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@Leci37
Copy link

Leci37 commented Jan 7, 2023

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
If you want edit, Plot code here : https://github.com/Leci37/stocks-prediction-Machine-learning-RealTime-TensorFlow/blob/master/Utils/Utils_plotter.py#L399
Feel free to improve and share, in case of error.
Usage: https://github.com/Leci37/stocks-prediction-Machine-learning-RealTime-TensorFlow/blob/master/technical_indicators/talib_technical_PY_TI.py#L143

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
@Leci37 Leci37 added the enhancement New feature or request label Jan 7, 2023
@twopirllc
Copy link
Owner

Hello @Leci37,

Awesome! Hopefully you or someone else can make a PR based off the development branch to get it integrated with the library sooner.

Kind Regards
KJ

@mariachi9999
Copy link

mariachi9999 commented Apr 1, 2023

Hi!
First at all, thank you so much for your effort! It´s great!
I have some problems with it, please could you check it?

Traceback (most recent call last):
File "C:\Users\Usuario\anaconda3\envs\trading-system-env\lib\site-packages\pandas\core\ops\array_ops.py", line 165, in _na_arithmetic_op
result = func(left, right)
File "C:\Users\Usuario\anaconda3\envs\trading-system-env\lib\site-packages\pandas\core\computation\expressions.py", line 241, in evaluate
return _evaluate(op, op_str, a, b) # type: ignore[misc]
File "C:\Users\Usuario\anaconda3\envs\trading-system-env\lib\site-packages\pandas\core\computation\expressions.py", line 70, in _evaluate_standard
return op(a, b)
TypeError: unsupported operand type(s) for /: 'str' and 'int'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Usuario\Desktop\Dev\projects\crypto-bot\screener_crypto.py", line 36, in
df = get_konkorde_params(df)
File "C:\Users\Usuario\Desktop\Dev\projects\crypto-bot\trading_indicators.py", line 7, in get_konkorde_params
tprice = (df_stocks['Open'] + df_stocks['High'] + df_stocks['Low'] + df_stocks['Close']) / 4
File "C:\Users\Usuario\anaconda3\envs\trading-system-env\lib\site-packages\pandas\core\ops\common.py", line 72, in new_method
return method(self, other)
File "C:\Users\Usuario\anaconda3\envs\trading-system-env\lib\site-packages\pandas\core\arraylike.py", line 126, in truediv
return self._arith_method(other, operator.truediv)
File "C:\Users\Usuario\anaconda3\envs\trading-system-env\lib\site-packages\pandas\core\series.py", line 6259, in _arith_method
return base.IndexOpsMixin._arith_method(self, other, op)
File "C:\Users\Usuario\anaconda3\envs\trading-system-env\lib\site-packages\pandas\core\base.py", line 1325, in _arith_method
result = ops.arithmetic_op(lvalues, rvalues, op)
File "C:\Users\Usuario\anaconda3\envs\trading-system-env\lib\site-packages\pandas\core\ops\array_ops.py", line 226, in arithmetic_op
res_values = _na_arithmetic_op(left, right, op) # type: ignore[arg-type]
File "C:\Users\Usuario\anaconda3\envs\trading-system-env\lib\site-packages\pandas\core\ops\array_ops.py", line 172, in _na_arithmetic_op
result = _masked_arith_op(left, right, op)
File "C:\Users\Usuario\anaconda3\envs\trading-system-env\lib\site-packages\pandas\core\ops\array_ops.py", line 129, in _masked_arith_op
result[mask] = op(xrav[mask], y)
TypeError: unsupported operand type(s) for /: 'str' and 'int'

@mariachi9999
Copy link

Already solve it...I leave the Q&A in case someone´s the same problem...

Sometimes the df has some values as strings...
The solution is to use pd.to_numeric() an convert this values en NaN, allowing the calculations.

Example:
df['Close'] = pd.to_numeric(df['Close'], errors='coerce')

Thanks!

@Leci37 Leci37 changed the title Blai5 Koncorde by manboto Python Koncorde by manboto Python Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants