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

Please add tradingview RMA indicator #141

Open
2W-12 opened this issue Jan 7, 2021 · 7 comments
Open

Please add tradingview RMA indicator #141

2W-12 opened this issue Jan 7, 2021 · 7 comments
Labels
Enhancement New feature or request Good first issue Good for newcomers

Comments

@2W-12
Copy link

2W-12 commented Jan 7, 2021

Hi,
any ideas how to implement TradingView Pine RMA ?

@xmatthias
Copy link
Member

hm, based on the description, it might be something around the following:

dataframe['rsi'] = ta.RSI(dataframe)
# Either ta-lib
dataframe['rma'] = ta.EMA(dataframe, price='rsi')
# or native pandas
dataframe['rma'] = dataframe['rsi'].rolling(window).ewm()

Now the big problem is how the EMA is calculated.
pandas allows multiple parameters to specify the calculation algorithm - but i'm not sure which one gives 1/alpha.

I'm also not sure how ta-lib calculates it precisely - and their docs in this regards is quite lacking.

@xmatthias xmatthias added Enhancement New feature or request Good first issue Good for newcomers labels Jan 7, 2021
@2W-12
Copy link
Author

2W-12 commented Jan 7, 2021

Unfortunately it doesn't give correct results.

Example:

close = np.array([4086.29, 4310.01, 4509.08, 4130.37, 3699.99, 3660.02, 4378.48, 4640.0, 5709.99, 5950.02])
# with period=3 on tradingview   rma(close, 3) will give following results
rma = np.array([np.nan, np.nan, 4301.79333333, 4244.65222222, 4063.09814815, 3928.73876543, 4078.65251029, 4265.76834019, 4747.17556013, 5148.12370675])

@xmatthias
Copy link
Member

As mentioned above - the parameters for the ewm() function in pandas are up to testing / analysis - as there's different ways to calculate a EMA ... pandas should support most of them - but how to configure them is ... not well documented if you ask me.

@synackSA
Copy link

You could try this library instead and see if it gives better results: https://technical-analysis-library-in-python.readthedocs.io/en/latest/ta.html

@renu285
Copy link

renu285 commented Nov 2, 2021

Any update on this?

@C0D3D3V
Copy link

C0D3D3V commented Jan 17, 2022

@2W-12 The following is pretty close to what you want:
Are you sure your rma result from TradingView is correct, how did you observe the results?

df = pd.DataFrame(data=[4086.29, 4310.01, 4509.08, 4130.37, 3699.99, 3660.02, 4378.48, 4640.0, 5709.99, 5950.02], columns=['close'])
length=3
df['close'].ewm(alpha=(1.0/length),adjust=False,min_periods=length).mean()

Result:

0            NaN
1            NaN
2    4276.935556
3    4228.080370
4    4052.050247
5    3921.373498
6    4073.742332
7    4262.494888
8    4744.993259
9    5146.668839
Name: close, dtype: float64

@C0D3D3V
Copy link

C0D3D3V commented Jan 17, 2022

TradingView forces the first entry to be the SMA of the first n entries, so the following leads to exactly the same result:

import pandas as pd
pd.set_option("display.precision", 8)
df = pd.DataFrame(data=[4086.29, 4310.01, 4509.08, 4130.37, 3699.99, 3660.02, 4378.48, 4640.0, 5709.99, 5950.02], columns=['close'])
length=3
df['rma'] = df['close'].copy()
df['rma'].iloc[:length] = df['rma'].rolling(length).mean().iloc[:length]
df['rma'] = df['rma'].ewm(alpha=(1.0/length),adjust=False).mean()

Result:

     close            rma
0  4086.29            NaN
1  4310.01            NaN
2  4509.08  4301.79333333
3  4130.37  4244.65222222
4  3699.99  4063.09814815
5  3660.02  3928.73876543
6  4378.48  4078.65251029
7  4640.00  4265.76834019
8  5709.99  4747.17556013
9  5950.02  5148.12370675

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants