Average close price for the last 10 years

Can someone show me a formula that returns the average close price for a stock over the last 10 years? I am unable to find examples of this.

Specifically, for each year I would like an average close price. Do this for 10 years. Return the 10 year average price.

I’m sure it’s a simple, but the closest I have come is something like this.

Avg(LowVal(252,252,#Low),LowVal(252,500,#Low)…LowVal(252,2000,#Low))

Much appreciated.

I have not found a way. The SMA function can’t do it because it is limited to a 500 bar (~2 year) offset. LoopSum can’t do it either because it can only handle 50 iterations or so.

Exactly. I have also looked at Aggregate and ItemA, but unable to see how these would work. It seems simple enough, however, maybe not?

Are you trying to re-create some factor? Maybe the PE10?

Maybe easier for us to just add the factor

ItemA is for fundamental line items

No I don’t think so, but I’m not familiar with how the factors work. I am trying to only include companies in my screen that are within x% of their 10 year average price.

I think loopsum , even with 50 iterations limit, works pretty well. THese are companies within +/- 5% of their 10 year average : 50 samples, 50 bars apart for a total span of 2500 bars which is approx 10 years.

setvar(@avg,loopsum(“close(ctr)”,50,0,50,true)/50) // note the last parameter true to not skip NAs (companies with less than 10y)
between(close(0)/@avg,0.95,1.05)

I’ve never notice ‘between’. Sweet.

Thanks Marco, exactly what I was looking for.