mdeverdelhan / ta4j-origins

A Java library for technical analysis ***Not maintained anymore, kept for archival purposes, see #192***
https://github.com/mdeverdelhan/ta4j/issues/192
MIT License
376 stars 223 forks source link

Average gain and average loss with memory. #46

Closed rsrtime closed 8 years ago

rsrtime commented 9 years ago

There are two ways of calculating average gain and average loss.

Without memory: Average Gain = Sum of Gains over the past period / period Average Loss = Sum of Losses over the past period / period

With memory: Average Gain = [(previous Average Gain) x (period -1) + current Gain] / period Average Loss = [(previous Average Loss) x (period - 1) + current Loss] / period

http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:relative_strength_index_rsi

Is there any plan to add an option to use the indicator with memory?

mdeverdelhan commented 9 years ago

No... But you can make a PR. :)

Please just note that I don't like boolean flags like "activateWithMemoryCalculation" (hard to document, hard to maintain, has to be tested, keeping both ways not obviously relevant, etc.) . I think you should simply replace the current calculation by your "with-memory" one. (By the way, both calculations are with memory in a sense. The difference may be more between an iterative way and a recursive one.)

If you have to courage to do that: don't forget you will have to update the tests for average gain, average loss, RSI and all related indicators and/or examples. That may be a lot of work for an uncertain gain.

Other questions: which case led you to this need? Which case got you thinking that using the recursive way should significantly change the behavior of your strategy?

rsrtime commented 9 years ago

The two different calculations of average losses/gains give different RSI values. For example, Google finance uses the calculation without "memory" and tradingview uses the "memory" calculation. Some ticks have completely different values for RSI depending what site is used. I want it because I prefer using tradingview's charts.

I was thinking of having two versions of the average gains/losses calculations in order to have the option to use either one. Maybe pass the indicator into the RSI constructor since the RSI calculation does not change.

mdeverdelhan commented 9 years ago

Erf. Finally I don't think it's worthwhile.

Of course we could do such an evolution (giving average gains/losses as RSI's arguments), but it would raise lots of new questions. E.g.:

It would also need numerous checks for limit cases (nullity, ...).

All that stuff would need to be tested, documented, maintained, etc. on a long-term footing.

I want ta4j to contains some useful and representative indicators but not all those conceivable (soon it would become unmaintainable, at least by me). I think that you should implement your versions (using ta4j's API) and keep them in your project.

In any case, thank you for your offer! Feel free to submit other original indicators, design improvements, tests, what-you-want...