3 Quarters Moving Average
Author: Specnomics10
Creation Date: 9/15/2020 1:11 PM
profile picture

Specnomics10

#1
Hello,

I'm trying to create a 3 Quarter Moving Average that recognizes March, June, September, and December as the quarters. What I am currently seeing is that the program assumes the latest trading day is the end of the latest quarter.

As way of an example, the current 3 quarter moving average should be computed using Dec '19, Mar '20 and June '20 month end close prices. But its currently using Mar'20, June '20 and 14-Sep-2020 prices.

Thanks
profile picture

Eugene

#2
Hi,

Here's how you can code it:

CODE:
Please log in to see this code.


Note the use of undocumented call (2nd line) to scale the MA to Quarterly scale.
profile picture

Specnomics10

#3
Thanks, I'll try that.
profile picture

Specnomics10

#4
Hi Eugene,

I'm still getting the same results i.e. ma_q for the latest trading date is being computed using the latest trading price. My expectation will be that latest ma_q only changes every quarter, but it changes everyday.

Using the example for FTSE100 in the attached screenshot, you can see the ma_q changing from the 14-Sep to 15-Sep; when it should be 7042.8901 - ma_q as at last quarter ending 30-June-2020.
profile picture

Eugene

#5
Hi Babatunde,

JPG is truly suboptimal for screenshots, PNG is a better choice:

JPEG or PNG – Which Image Format Offers Better Quality?

Now on to your question. If current bar doesn't represent an end of quarter you can simply ignore the change, right?

CODE:
Please log in to see this code.

profile picture

Specnomics10

#6
Still getting the same result i.e. quarterly ma is changing.

Re "...If current bar doesn't represent an end of quarter you can simply ignore the change, right?", not possible I am using the quarterly ma as the basis of structural momentum measure. see code below.

CODE:
Please log in to see this code.

profile picture

Eugene

#7
Look, I wasn't staing that the MA won't change. It doesn't matter if it does. You should simply make your trading system ignore the change on the last bar if it's still the same Quarter of the year. And that's what the code in my post #5 is intended to show.
profile picture

Specnomics10

#8
Thanks
profile picture

Eugene

#9
Any time.
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).