Understanding Binance RSI calculation
Hello, though this is not directly related to Backtrader anymore, but to the same data gathering+evaluation I figured someone here might be proficient in: I am having trouble replicating the exact way in which Binance calculates their RSI. Take this date as an example:
My backtest bought in at the 4 o'clock candle, because the 3:55 one had a really low RSI. Binance says the RSI(12) was 9.47, while my function returned a 14.63 for the same intervals. I checked those intervals via printout and even calculated the RSI by hand, getting 14.63 as well.
Then I researched the problem and found someone mentioning that Binance might use some exponential average instead, and that using "talib" solved that problem. So I got talib running and through much more unwieldy and inefficient code.(numpy array conversion. then output is a list of measurements instead of the one RSI I only need at the end)
...Well, the result is exactly the same, 14.63 for that test score, and also identical for all other ones, so either there is no other RSI method, or talib requires some other leavers be pulled to get Binances different results. I tried finding that in the documentation, but was unsuccessful.
You can see the list of values in question in the second screenshot printed before the first date. How can this be mixed towards a RSI of 9.47?
This is important for me to replicate, since I use the graphical interface of Binance to come up with strategy hypotheses, so if the indicator values don't match up, my own backtest can't properly act those strategies out, leaving them unvetted.
@solo-kirmish I don't know if this has anything to do with it, but I have had issues with indicators being 'off' due to the bar alignment. Check to see if binance is using start of bar vs. end of bar.
@run-out Thank you for the tip. Sadly, that only makes the RSI even higher to 15-something, so this isn't it.
@solo-kirmish That's too bad. It can be frustrating matching another outside indicator when you have no true insight into what they are doing. Good luck.
The more I look into it, the more it becomes obvious that the Binance RSI is no RSI at all, but some other undisclosed type of measurement. I see it being at odds at every value with both talib and my implementation, but what strikes most is that the Binance (so called) "RSI" is much more stable for some reasons.
For evidence, let's look at this:
In the marked section from 15:55 to 16:45 the Binance RSI(12) peaks exactly at the high 15:55 candle with just about 60, then declines gradually in a linear fashion.(with the exception of that one tiny uptick at the exact only green candle in this decline) The RSI reaches its lowest point exactly at the price local lowest point.
Now in contrast talib RSI:
These measurements are intentionally offset by +5min since they are meant to be fed into decision making for the current candle, but you can see a similar high at 16:00 (which is the 15:55 RSI) of 59.65. Some critical difference with it not reaching 60, but so far so good. What is most striking however, is that the talib RSI (and mine) actually take up during the price decline.
This is caused by the moving average "forgetting" reference to the extreme negative candles to the far left, while still holding on to the powerful green uptick in the middle left, so the slow decline after the 15:55 peak is actually not judged as being weighty enough.
That of course is a stark contrast to the, again, linear decline of Binances so called "RSI" that snuggles its ups and downs completely around the general price trend. Thus, the conventional wisdom RSI and what Binance calls RSI cannot be the same thing, since the RSI formula would have to be changed in ways that completely distance it from the original purpose to achieve this effect.
If anything, this reminds me more of the Exponentially Weighted Average from machine learning, where you would essentially just take a percentage of the last, say, RSI, and then add the remaining percentage of the current RSI to get some slight but not overshadowing shift.
Like this (0<=Beta<=1):
The RSI right would be the known formula, but the displayed "RSI", the Binance-RSI, would be a moving average, which would probably work in this snuggle and flattening effect.
What do you people say? Is this known?
Just to report back, I had success!
The theory was correct in that there is actually this smoothing "step 2" RSI as I found out it is called, which was calculated somewhat similar to the formula above. However, it was very nebulous how it would exactly be implemented, so I had to do a full day of trial, error and horror.
Well, I was able to reproduce the Binance RSI(6) now, with values matching to the T. This is already pretty much enough for me, though I have to wonder whatever these other values, RSI(12) and RSI(24) of Binance are. Certainly that number doesn't reference the time period anymore, since I can't get even remotely the same values using the same method I employed for RSI(6). In fact, even just increasing the smoothing period to 7 causes my RSI to sometimes overshoot over Binance RSI(12), and in some cases even RSI(24)!
An actual period of 24 generates in fact so much smoothing that the RSI is barely making it out of the 40-60 range most of the time.
If someone has an idea what is going on, and why the RSI(12) and RSI(24) would be calculated so differently, I am open to suggestions.
One of my guesses is that they might in some way reduce the relevance of values beyond t=6, so maybe 7-12 only applies at half value, and 13-24 might only be used at 25% or something in that direction.
Btw., I find it markedly difficult to find any information about these topics, not just with Binance. There aren't really many forums, even stackoverflow-clones and such around to ask these questions, and in the few that exist, there is somehow near 0 activity.
Maybe I am just in the wrong place asking these specifics in this forum, but out of the list of options, it simply appears the most professional in approach. If you however have knowledge about a place where my question would be better off, please don't hesitate to tell me, - I won't be insulted, because I am actually searching for a place to talk about this too.
@solo-kirmish IMHO, if you are trading off an indicator on a system where you have no insight into how the indicator is calculated, throw it in the gabage. It's a magic box you have no control over.
The second thing I would point out is, what's so special about it anyway? Do they have some sort of secret sauce for making money with that formula? If they do, it's probably traded out of the market by everyone else. So again, throw it in the garbage.
And what if you do adopt it? And MAKE MONEY!! Then all of a sudden it starts not making money, or behaving differently. How will you be able to know if it changed? ..doesn't work anymore? Or its just bad luck. Will it get batter again? Well, at that point, you'll throw it in the garbage. Maybe you can make some money on it, but you might as well take a good penny stock tip from that guy, you know, you met in the bar last tuesday.
This is also btw, probably why you are not seeing a lot of interest in solving this riddle. Nobody cares.
Just my two cents.
@run-out He, well I am very well aware that using official indicators is not a good move usually, just because too many would already be using it. This is why I too have built my past strategies on custom tailored indication and always shun away from all these "easy" make rich scheme indicators, especially RSI with its "buy 30 sell 70 be rich" lazy and untrue success formula that I see repeated everywhere.
I am still not doing that however, but I seek to automate normalization, for which I have observed RSI is a pretty good candidate. This recent boom in BTC has caused proven strategies to be thrown out of the window, simply because interval-volume has increased more than tenfold in just a year, and thus also the turbulence has increased. I managed to devise a pretty promising strategy for the range of 1.1.21 to end of February, but the problem is, it doesn't scale back to last year at all, while of course the old strategies don't apply to this new craze.
I have since though about a machine learning learned scaler variable plan, but it is elaborate and takes too much time to implement for now. Since the market is in motion at this very moment, I simply try to find a heuristic scaling solution, and by observing the Binance RSI with its snuggle effect around price trends independent of their actual value, I just want to fish this out in order to normalize my strategy for the broader activity-scale spectrum. Ambitious perhaps, but I will see if it is really any better than my current work.
So be reassured that I wont do some simplistic buy/sell-margin foolishness here. ;)
Also, the workings of the Binance RSI(6) indicator are decrypted, and there are no shenanigans in the calculation other than that it is difficult to follow up on how the implementation would work. I doubt they would ever just change that, but even if, the fear that any strategy would collapse because of that change is unfounded I think, since I don't extract their indicator, but replicated it. So if whatever I do with it works out, I will just keep it no matter what Binance does later on.
Now what they do with RSI(12) and RSI(24) is still a mystery, but if knew, I reckon it would play out the same.