ALMA (Arnaud Legoux Moving Average)
Author: Darrell__
Creation Date: 9/3/2017 6:41 PM
profile picture

Darrell__

#1
I might be not be interpreting this code correctly, but looking at the source code for the ALMA (community) indicator below, it appears the indicator is using a future data point in its calculation. For example, if the current data series index (j) is 100, with a window size of 9, with "i" (window index) = 9; wouldn't the data series index, ds[j - (windowSize - 1 - i)], = 101, i.e. one data point in the future?

CODE:
Please log in to see this code.


Is the code incorrect, or am I missing something? Any thoughts?
profile picture

Eugene

#2
100(j) - 9(windowSize) - 1 - 9(i) = 81

How do you get 101?

P.S. Here's where the code comes from: Can someone translate this No Lag Moving Average code?
profile picture

Darrell__

#3
Now I am really confused. But here is how I got 101:

ds[j - (windowSize - 1 - i)]

j = 100
windowSize = 9
i = 9

therefore,

j - (windowSize - 1 - i) equals 100 - (9 - 1 - 9) = 100 - (-1) = 101


profile picture

Eugene

#4
Thanks, now I see: I didn't pay attention to the braces. Makes sense now.

It corresponds to the following line in the translation to SierraChart:
CODE:
Please log in to see this code.


The original MQL code has it like this:
CODE:
Please log in to see this code.
profile picture

Darrell__

#5
Eugene,

I'm not sure if I am correct on this, but I think the discrepancy has to do with zero based indexing in the original (SierraChart and MQL) code vice one based indexing in the community indicators code. I think that if you use one based indexing then you may need to change the code to:

CODE:
Please log in to see this code.


Unfortunately, I don't have another implementation to verify the results using the change above. Then again, I could be entirely wrong.

best regards...
profile picture

Eugene

#6
Darrell,

I revisited your original post and the code and it seems to me that the condition that worries you shouldn't take place:
QUOTE:
with a window size of 9, with "i" (window index) = 9;

As you can see from the condition in the loop, "windowSize" cannot be equal to "i":
CODE:
Please log in to see this code.

And since "i" is less than the "windowSize" then:

j - (windowSize - 1 - i) equals 100 - (9 - 1 - 8) = 100 - (0) = 100

Problem solved?
profile picture

Darrell__

#7
Eugene,

OK... my mistake, you are right as usual. However, since each version uses the same upper limit, i.e. "i < windowSize"; my gut feeling is that the window size in the original source (using zero based indexing) is not the same as the community indicator which uses one based indexing. But w[0] in the the original source code is so small, any difference should be insignificant.

Thanks again for responding...
profile picture

Eugene

#8
You're welcome.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).