Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

initial RSI values are calculated wrong #2583

Closed
mmdiego opened this issue Dec 27, 2020 · 15 comments
Closed

initial RSI values are calculated wrong #2583

mmdiego opened this issue Dec 27, 2020 · 15 comments

Comments

@mmdiego
Copy link
Contributor

mmdiego commented Dec 27, 2020

Comparing RSI indicator values with Binance exchange, I've realized they were wrong. Debugging RSI indicator code, I've found the initial calculation (when the sum of gains and losses is made) is handled incorrectly as it uses the values from s.loopback array that are in reversed time order, so it is considering every gain as a lose and viceversa.
Reversing the array fixes the problem, I'll commit the fix soon.

mmdiego added a commit to mmdiego/zenbot that referenced this issue Dec 27, 2020
@XL-Reaper
Copy link
Contributor

How did you get the values from Zenbot? I can't see the RSI in the simulation results.

@mmdiego
Copy link
Contributor Author

mmdiego commented Dec 28, 2020

Using the RSI indicator, is that what you are asking?
RSI indicator is implemented in lib/rsi.js
and you can check how to use it in some of the example strategies

@XL-Reaper
Copy link
Contributor

No I meant the actual RSI values. You say they are wrong, but where do you get to see that wrong number? The simulation does not put out RSI values - at least for me.

@k3ntinhu
Copy link
Contributor

k3ntinhu commented Dec 28, 2020 via email

@XL-Reaper
Copy link
Contributor

https://en.wikipedia.org/wiki/Thank_You

So you actually just have to enable verbose output to see these.
I've compared the results from before & after the requested change: The RSI values stay the same.
Also they don't look wrong to me when I compare them to TradingView for instance.

@mmdiego
Copy link
Contributor Author

mmdiego commented Dec 28, 2020

Sorry, yes, that's right, you need to enable verbose output and they are shown in one of the columns.
Regarding the values, only the first values are wrong, but the RSI tend to converge to the right value after some periods, as only the initial average is done wrong, but following period values are used correctly.
I'll try to post some captures later.
Do you have your compare results to show?

@XL-Reaper
Copy link
Contributor

I'm comparing Kraken XBT - USD https://www.tradingview.com/chart/?symbol=KRAKEN%3AXBTUSD

5M Period between 2020-12-28 08:15:00 - 2020-12-28 08:35:00
All the RSI values of the simulation match.

2020-12-28 08:15:00 26797.00 XXBT-ZUSD -0.28% 118 --- 34.35 -0.00192 0.0000 34.35 0.005
2020-12-28 08:20:00 26691.40 XXBT-ZUSD -0.40% 306 --- 29.32 -0.00585 0.0000 29.32 0.005
2020-12-28 08:25:00 26758.40 XXBT-ZUSD +0.25% 35 -- 35.75 -0.00335 0.0000 35.75 0.005
2020-12-28 08:30:00 26857.80 XXBT-ZUSD +0.37% 9 -- 43.91 0.00035 0.0000 43.91 0.005
2020-12-28 08:35:00 26997.50 XXBT-ZUSD +0.52% 279 52.94 + 0.00555 0.0000 52.94 0.005

@mmdiego
Copy link
Contributor Author

mmdiego commented Dec 28, 2020

I'm using Binance but with TradingView graphs also.
I'll check the values later. However, I do see a difference before and after the change I'm proposing
Can you show me the command you used to run the simulation for your results?

@XL-Reaper
Copy link
Contributor

I run from docker:
docker-compose exec server zenbot sim kraken.XXBT-ZUSD --strategy trend_ema --verbose --rsi_periods=14 --days=1 --period=5m

If I change the file, the results (at least in that timeframe that I mentioned) don't change for me

@mmdiego
Copy link
Contributor Author

mmdiego commented Dec 28, 2020

Thank you. I think I know where the "problem" is. Trend_ema uses a min_periods value of 52, which give RSI enough old data to converge to right values after many periods as I said.
But if you try another strategy (i.e.: noop) and set min_periods to the minimum periods you need for RSI indicator, you should see the differences I'm talking about.
Try:
docker-compose exec server zenbot sim kraken.XXBT-ZUSD --strategy=noop --verbose --rsi_periods=14 --days=1 --period=5m
and compare results against TradingView with and without my modification

@XL-Reaper
Copy link
Contributor

Even with the command you suggested the RSI values don't change for me.
Which command are you running and which values do you get? Let me try to reproduce your results :)

@mmdiego
Copy link
Contributor Author

mmdiego commented Dec 28, 2020

Check out this: have a look at RSI value at 9.55. On Binance and RSI fixed is around 70, but with old RSI is 34. Try to replicate this simulations.

Binance RSI:
image

RSI old:
image

RSI fixed:
image

DeviaVir pushed a commit that referenced this issue Dec 29, 2020
@DeviaVir
Copy link
Owner

Merged your PR (thanks for contributing that!), good to close this?

@XL-Reaper
Copy link
Contributor

Took me a while to notice we were on different time zones hahaha.
Anyways: Yeah, with the short min_periods the discrepancy between the calculated RSI and the Binance RSI is visible. When you apply the standard longer periods the difference is just in the decimals.

@mmdiego
Copy link
Contributor Author

mmdiego commented Dec 29, 2020

Cool! Thank you for taking your time to check it.
I'll close it

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

No branches or pull requests

4 participants