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.
Size:
Color:
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.
Size:
Color:
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.
Size:
Color:
Yes, it did work ! Thanks for this.
Size:
Color: