cinar / indicator

Indicator is a Golang module that provides a rich set of technical analysis indicators, strategies, and a framework for backtesting.
GNU Affero General Public License v3.0
526 stars 103 forks source link

Lower Acceleration Band Value is incorrect #7

Closed liamwh closed 3 years ago

liamwh commented 3 years ago

Maths for acceleration lower band appears to be incorrect image

Expected: 1m: image

15m: image

1h: image

To Reproduce image + image

Expected behavior Formula to calculate the lower band would correlate with the following pinescript: image

Additional context Just wanted to say I'm loving using the package, thanks for your great work Cinar! I would be absolutely willing to contribute but maths really isn't my strong suit 😅

cinar commented 3 years ago

Thank you very much Liam for filing the issue. Let me compare the calculations and fix it. I can definitely use your help to validate it.

liamwh commented 3 years ago

Thank you very much Liam for filing the issue. Let me compare the calculations and fix it. I can definitely use your help to validate it.

No problem, just let me know which branch to pull and I'll happily share the results of my testing! 👍

Cheers Cinar!

liamwh commented 3 years ago

For what it's worth, as a cheat / workaround, I've written this:

func AccelerationBands(high, low, close []float64) ([]float64, []float64, []float64) {
    checkSameSize(high, low, close)

    k := addBy(multiplyBy(divide(substract(high, low), add(high, low)), 4), 1)

    upperBand := Sma(20, multiply(high, k))
    middleBand := Sma(20, close)
    var lowerBand []float64
    for i, upperValue := range upperBand {
        lowerBand = append(lowerBand, (middleBand[i] - (upperValue - middleBand[i])))
    }

    return upperBand, middleBand, lowerBand
}
cinar commented 3 years ago

Hi Liam, I found a mistake in lower band calculation. Could you try with v1.2.4 to see if it fixed the problem for your calculation?

liamwh commented 3 years ago

Hi Liam, I found a mistake in lower band calculation. Could you try with v1.2.4 to see if it fixed the problem for your calculation?

It's perfect now, great work and thanks again Cinar!

cinar commented 3 years ago

Hi Liam, you are very welcome, I am glad to hear that it worked.

I am trying to identify the next set of technical indicators to include to the module. If there any specific ones that you like to see included please let me know by filing an issue. Many thanks!