-
Notifications
You must be signed in to change notification settings - Fork 129
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
RSI value does NOT match expected values #46
Comments
My thinking process:ta EMA's k = What makes: For example. with
What means, TA's EMA puts more weight on the most recent input than the old ones. How to fixThe difference between to formulas is so significant, that it would definitely break working strategies. Maybe of possible solutions would be:
|
Apologies for the mistake in my recollection of your formula for alpha. Yes, the default should remain the same. What I had done in my local fork is add a different constructor It could be better to create a generic struct with a type parameter for this, like trait EmaConfig {
fn compute_alpha(period: usize) -> f64;
}
struct DefaultEMAConfig;
impl EmaConfig for DefaultEmaConfig {
fn compute_alpha(p: usize) -> f64 { 2.0 / (period as f64 + 1.0) }
}
struct TradingViewEMAConfig;
impl EmaConfig for TradingViewEMAConfig {
fn compute_alpha(p: usize) -> f64 { 1.0 / period as f64 }
}
pub struct GenericRSI<E: EmaConfig> { ... }
pub type RSI = GenericRSI<DefaultEmaConfig>;
pub type TVRSI = GenericRSI<TradingViewEMAConfig>; The simple way however: struct Ema { ... }
impl Ema {
fn set_alpha(&mut self, a: f64) { ... }
}
impl RSI {
fn set_alpha(&mut self, a: f64) { ... }
} After compilation the default alpha and the manual override of alpha should simplify away the original assignment & be zero cost. It could be more elegant to use the generic approach however. By the way are these two versions of the EMA / RSI named something different? Not cool if the financial community just throws around the name RSI and acknowledges the period as a parameter but not how the alpha parameter is computed! Yields completely different values! |
Hello guys, I also met this issue when I was using RSI indicator. Is there any plan or good solution to solve this issue? I just changed the k of EMA temporarily to fix it. |
what about this? for EMA, we can pass a value of period or alpha, just select one ( like pandas library )
then in RSI
|
Hi, I have the same issue not only with RSI but also with SlowStochastic and FastStochastic. Both of them don't match the values that I can see in platforms like TV. Any expectation about when it could be solved? |
just something i've encountered in the past, make sure you're using standard candles and not heiken ashi |
My bad. Both Stochs are correct. I was using the wrong data. |
Pinescript v5 doc says https://www.tradingview.com/pine-script-reference/#fun_ta{dot}ema v4 is the same. |
Pinescript's struct AverageTrueRange<M=RelativeMovingAverage> |
I am confirming that there is a bug with RSI. I used ChatGPT to help diagnose and fix the bug. Here's an excerpt: The array is [(t1,10), (t2, 10.5), (t3, 10), (t4,9.5)]. Each tuple represents a time point (t1, t2, etc.) and the corresponding price. Steps for calculating the 3-day RSI: Calculate Daily Price Changes: Subtract the previous day's price from the current day's price. Daily Price Changes: From t1 to t2: From t2 to t3: From t3 to t4: Gains and Losses: __ Average Gain: Calculate RS: RS = Average Gain / Average Loss = Calculate RSI: However, the unit tests here have the following (wrong) unit test:
I forked the repo to fix these issues and also made it easier to have a dynamic window size. |
Hello,
I've been using the RSI indicator provided by
ta
.Using the RSI indicator, I compute some higher level indicators, their form is not important here.
I wanted to verify that I had implemented the indicator correctly, and so I wrote extensive test cases on real data lifted from TradingView.
This is when I noticed that the RSI value computed on TradingView does not match the RSI computed from this library.
I figured out the issues here:
ta
RSI use a different alpha (k
field), as2 / (period - 1)
, whereas on TV, the RSI uses an EMA with alpha of1.0 / period
.I am not sure which version of the RSI is the intended "official" RSI,
but in order to make the RSI implementations match I've had to change things inside the
ta
library.If you have any information on this please let me know, I am a bit clueless.
My suggested change is that you provide a function on
EMA
and dependent indicators to set the alpha parameter used.The text was updated successfully, but these errors were encountered: