amv-dev / yata

Yet Another Technical Analysis library [for Rust]
Apache License 2.0
321 stars 49 forks source link

ADI seems incorrect? #29

Closed All8Up closed 1 year ago

All8Up commented 1 year ago

Hi folks, while working on a little Alpaca experiment, I was looking at yata and ended up poking at the adi method. Unfortunately, in testing things out, it gave me rather bad data. Looking at the code, it seems that it is using the clv against the single bar inputs rather than the 'day' low/high, which as I understand it is not correct? When I plugged in a custom implementation based on the days values, it seemed to correct the problem. Perhaps I'm reading it incorrectly?

amv-dev commented 1 year ago

Hello! I don't understand what do you mean by saying that using clv is incorrect. ADI method is described here https://en.wikipedia.org/wiki/Accumulation/distribution_index and it's implemented in yata just like this. Can you provide some additional data?

All8Up commented 1 year ago

From the linked article, emphasis added: "This ranges from -1 when the close is the low of the day". I'm fairly sure they mean that low/high in this context is not the low/high of the individual bar but the low/high of the day up to the point of the computation. I could still be reading it wrong but when I plotted things out and compared to trading view, making low/high the day low/high rather than the bar low/high looked much more accurate.

amv-dev commented 1 year ago

I think it's just a mistake in the article. There are tons of problems if we consider using daily highs and lows. For example, you can't use ADI on week or month data. The whole indicator became inconsistent. Here is another article and it's strictly says that we should use period values: https://www.investopedia.com/terms/a/accumulationdistribution.asp

All8Up commented 1 year ago

In reading the new article you listed, I still believe that even that one is pointing out the "current" close versus the high low being for the entire period. But, at the same time I believe I know how to interpret it and where my disconnect came from. ADI, when displayed at a less than 1 day resolution is computed as the current state of the entire live session as if it were a partial "day" bar. While that may have been obvious to you, I missed it and as such was incrementally building the ADI from the minute bars which is just all sorts of wrong. When I tracked the low/high it got closer simply because at that point I was properly feeding it partial "day" bars but it was still incorrect since I defaulted it with a window size and that was not matching TradingView either. Zero the window and the shape actually matches now, but obviously doesn't start at the same point since they seed it with the prior "day" adi...

Blah, I really hate multi-resolution indicators on TradingView when they don't bother to point out they are actually multi-resolution.... Unfortunately, I don't believe I can use the incremental yata implementation if I want a 1:1 match, but I only need it for the current session and only care about direction so, hopefully it will work in my setup now that I understand the gotcha's....