Effacer les filtres
Effacer les filtres

How to calculate moving average excluding current data?

2 vues (au cours des 30 derniers jours)
liu James
liu James le 27 Nov 2016
Commenté : dpb le 28 Nov 2016
How to calculate moving average to not include current data for the current period. For example, I'm trying to create the Donchian Channel and the formula is the 20 high or 20 low of the preceding date. If so, this should not include the current date. All the moving and tsmovavg includes the current date.

Réponses (1)

dpb
dpb le 27 Nov 2016
N=20; % number above/below midpoint
u=[ones(1,N) 0 ones(1,N)]/(2*N-1); % weighting
mAvg0=conv(data,u,'valid');
  4 commentaires
Image Analyst
Image Analyst le 27 Nov 2016
It's just considering the N points to the right and left of the current point. The center point (i.e. the "current" point) has a weight of zero so it's not included in the sum.
dpb
dpb le 28 Nov 2016
>> [x;[nan conv(x,[1 0 1]/2,'valid') nan]]
ans =
1 2 3 4 5 6 7 8 9 10
NaN 2 3 4 5 6 7 8 9 NaN
>>
should make it patently clear, one would think???

Connectez-vous pour commenter.

Catégories

En savoir plus sur Preprocessing Data dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by