Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aroon Indicator #124

Open
Screpuh opened this issue Aug 16, 2023 · 2 comments
Open

Aroon Indicator #124

Screpuh opened this issue Aug 16, 2023 · 2 comments

Comments

@Screpuh
Copy link

Screpuh commented Aug 16, 2023

Describe the bug
The Aroon Indicator has the following error:

given the list of highs (lows the same but only use high in this example) it first calculates the highs with the Max function. This returns a list for i ... n where i the high for i - 25. Next it uses the function Since but this is not correct. The function since checks for value i when it last changed. But this is not what you want. You want to know for point i how many days was the last high.

Example high [48, 52, 50, 49, 10]

lets say window is 3 in this example. Max will return:

[48, 52, 52, 52, 50]

Since would be in this case:
[0, 0, 1, 2, 0]

In the aroon calculation you do 3 - sinceLastHigh / 3 * 100

for n this would be (3 - 0) / 3 * 100

It thinks the amount of days since the last high is 0 which is wrong. I think you don't want to check since when the value changed but for value i how many days ago was the last high in a given period.

so for example instead of the function since() and max() use something like the following:

func SinceHigh(period int, values []float64) []int {
	result := make([]int, len(values))

	for i := 0; i < len(values); i++ {
		startIndex := i - period
		if startIndex < 0 {
			startIndex = 0
		}

		highest := math.Inf(-1)
		highestIndex := startIndex

		for j := startIndex; j <= i; j++ {
			if values[j] > highest {
				highest = values[j]
				highestIndex = j
			}
		}

		result[i] = i - highestIndex
	}

	return result
}

func SinceLow( period int, values []float64) []int {
	result := make([]int, len(values))

	for i := 0; i < len(values); i++ {
		startIndex := i - period
		if startIndex < 0 {
			startIndex = 0
		}

		lowest := math.Inf(1)
		lowestIndex := startIndex

		for j := startIndex; j <= i; j++ {
			if values[j] < lowest {
				lowest = values[j]
				lowestIndex = j
			}
		}

		result[i] = i - lowestIndex
	}

	return result
}

And then in Aroon do:
sinceLastHigh25 := SinceHigh(25, high)
sinceLastLow25 := SinceLow(25, low)

@cinar
Copy link
Owner

cinar commented Aug 16, 2023

Thank you very much for your detailed bug report. I think you are correct. If you want to send a PR, please feel free to do so. Otherwise, I'll fix it aligned with your note here. If you happen to have some test data that can be used for unit testing here please let me know as well.

@Screpuh
Copy link
Author

Screpuh commented Aug 16, 2023

It's ok to copy and paste this code so please feel free to do so,

you can test for SinceHigh

values := []float64{29503, 29515, 29527, 29579, 29631, 29665, 29490, 29449, 29420, 29438}
for period := 3
expected := []int{0, 0, 0, 0, 0, 0, 1, 2, 3, 3}

and for period = 5
expected := [0 0 0 0 0 0 1 2 3 4]

I guess you can make many more if you like :)

Please let me know if you need any more help

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

No branches or pull requests

2 participants