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

Variable Index Dynamic Average VIDYA #116

Closed
tarantula3535 opened this issue Sep 28, 2020 · 9 comments
Closed

Variable Index Dynamic Average VIDYA #116

tarantula3535 opened this issue Sep 28, 2020 · 9 comments

Comments

@tarantula3535
Copy link

https://tr.tradingview.com/script/64ynXU2e/
can anyone help write this indicator ?
it is a good filter..

@xmatthias
Copy link
Member

xmatthias commented Sep 29, 2020

I guess the following should work:

def VIDYA(dataframe, length=9, select=True):
    """
    Source: https://www.tradingview.com/script/64ynXU2e/
    Author: Tushar Chande
    Pinescript Author: KivancOzbilgic
    
    To achieve the goals, the indicator filters out the market fluctuations (noises) 
    by averaging the price values of the periods, over which it is calculated. 
    In the process, some extra value (weight) is added to the average prices, 
    as it is done during calculations of all weighted indicators, such as EMA , LWMA, and SMMA. 
    But during the VIDIYA indicator's calculation, every period's price 
    receives a weight increment adapted to the current market's volatility .
        
    select: True = CMO, False= StDev as volatility index
    usage:
      dataframe['VIDYA'] = VIDYA(dataframe)
    """
        df = dataframe.copy()
    alpha = 2 / (length + 1)
    df['momm'] = df['close'].diff()
    df['m1'] = np.where(df['momm'] >= 0, df['momm'], 0.0)
    df['m2'] = np.where(df['momm'] >= 0, 0.0, -df['momm'])
    
    df['sm1'] = df['m1'].rolling(length).sum()
    df['sm2'] = df['m2'].rolling(length).sum()
    
    df['chandeMO'] = 100 * (df['sm1'] - df['sm2']) / (df['sm1'] + df['sm2'])
    if select:
        df['k'] = abs(df['chandeMO']) / 100
    else:
        df['k'] = df['close'].rolling(length).std()
    df.fillna(0.0, inplace=True)

    df['VIDYA'] = 0.0
    for i in range(length, len(df)):
        
        df['VIDYA'].iat[i] = alpha * df['k'].iat[i] * df['close'].iat[i] + (1 - alpha * df['k'].iat[i]) * df['VIDYA'].iat[i-1]
    
    return df['VIDYA']

I'm no expert in pinescript though - so please help me validate this so we can add it to technical in the future.

@tarantula3535
Copy link
Author

thanks buddy i will try and inform you about it works properly...
I hope you took a look at my other indicator posts..
i checked it and they are working properly
supertrend , MADR , VWMACD , RMI ... and the others.. @xmatthias

@xmatthias
Copy link
Member

oh well, you bet (RMI + VWMACD + TKE are in #117) 👍

@tarantula3535
Copy link
Author

tarantula3535 commented Sep 29, 2020

thenx man i add my indicators file...that is corrrect results...thank you for help....
#117 I hope I could help..

xmatthias added a commit that referenced this issue Sep 30, 2020
@xmatthias
Copy link
Member

Thanks for the feedback, added it to #117 too.

@acemi1
Copy link

acemi1 commented Jul 21, 2022

hi, indicator calculation does not match tradingview.
I found a code that works correctly.
However, I am a beginner in python. I can't give you ready code.

#97 (comment)

@xmatthias
Copy link
Member

well the link is for a completely different indicator (OTT) - so i'm not sure how that comment is relevant here.

@acemi1
Copy link

acemi1 commented Jul 22, 2022

Thank you for the answer.
There is no error in the link. Calculating "vidya" in OTT indicator. Written as df['var'] in the code.
I took the relevant part in the code of the OTT indicator and tried to make it usable. The results are the same as with Tradindview.


def vidya (dataframe=df, length = 4, source="close"):

    alpha = 2 / (length + 1)
    df['ud1'] = np.where(df[source] > df[source].shift(1), (df[source] - df[source].shift()), 0)
    df['dd1'] = np.where(df[source] < df[source].shift(1), (df[source].shift() - df[source]), 0)
    df['UD'] = df['ud1'].rolling(9).sum()
    df['DD'] = df['dd1'].rolling(9).sum()
    df['CMO'] = ((df['UD'] - df['DD']) / (df['UD'] + df['DD'])).fillna(0).abs()


    df['Var'] = 0.0
    for i in range(length, len(df)):
        df['Var'].iat[i] = (alpha * df['CMO'].iat[i] * df[source].iat[i]) + (1 - alpha * df['CMO'].iat[i]) * \
                           df['Var'].iat[
                               i - 1]
    # print("vidya indicator\n", df['Var'])
    return df['Var']

vidya ()

vidya.py.txt

@xmatthias
Copy link
Member

If you think an indicator is wrong and you have a fix, please open a pull request submitting the fix (please with sample code/screenshots showing missalignment / new alignment with tradingview).

Please understand that i'll not be extracting code from issue comments - which will have me repeat the work you already did (compare it with tradingview, ...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants