Simple Moving average of alternate days
Author: nalin
Creation Date: 7/25/2014 1:10 AM
profile picture

nalin

#1
I'm trying to calculate simple moving averges of prices of alternate days. For example, after a week, I calculate a moving average of Friday, Wednesday, Monday etc and a second moving average of Thursday, Tuesday, the previous Friday etc.

In the code below I get the prices right in two data series i.e. 'earlier' and 'later', but when I calculate the SMA of these data series, I get the exact same values for both, whereas they should be different

I can't figure out what I'm doing wrong.

Any help would be appreciated.



CODE:
Please log in to see this code.
profile picture

Eugene

#2
You did not indicate which value should a series take on the preceding bar so I assume it's 0. Here's my take at it:

CODE:
Please log in to see this code.
profile picture

Cone

#3
The problem is your initialization of the earlier and later series - they both refer to the same DataSeries (Close - Close). If you initialize the DataSeries like Eugene did, your code will work.

CODE:
Please log in to see this code.
profile picture

nalin

#4
Yes, it did work ! Thanks for this.
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).