
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
this ma repaints? redraw?
Since this thread is already dealing with these, let us keep them together :
There is one more variation of Spencer's moving average : a 21 point moving average (previous one posted is 15 point moving average - I am using the name ("moving average") given to it at Wolfram's math world even though some are using "Spencer's filter" name) Some more information about the Spencer's 21 point moving average can be found here : Spencer's Formula -- from Wolfram MathWorld When you compare it to 15 point one it is even smoother, but, again, keep in mind that it is a centered moving average and in this one last 11 bars are a subject of changeActually I think what is meant by Spencer MA could be something like this:
{
ExtMapBuffer0=1/((iClose(0,0,i)/(-3))+(iClose(0,0,i+1)/(-6))+(iClose(0,0,i+2)/(-5))+(iClose(0,0,i+3)/3)+(iClose(0,0,i+4)/21)+(iClose(0,0,i+5)/46)+(iClose(0,0,i+6)/67)+(iClose(0,0,i+7)/74)+(iClose(0,0,i+8)/67)+(iClose(0,0,i+9)/46)+(iClose(0,0,i+10)/21)+(iClose(0,0,i+11)/3)+(iClose(0,0,i+12)/(-5))+(iClose(0,0,i+13)/(-6))+(iClose(0,0,i+14)/(-3)))/320;
//15 MA weights: -3,-6,-5, 3, 21, 46, 67, 74, 67, 46, 21, 3,-5,-6,-3 total sum is 320.
}I did the 1/ because the shape seemed inverted. It goes on the bottom of the chart; I think If you combine it with a 3rd degree regression it could be interesting.
Mrm
You are on a wrong path. The attached document contains a step-by-step formula evaluation for Spencer moving average (pages 5 to 9 - except that the way it is written it does not solve the "centering" part as the formula on Wolfram math world site, the rest is OK)
The one already posted ("Spencer moving average" indicator) is correct.
regards
Mladen
Actually I think what is meant by Spencer MA could be something like this:
{
ExtMapBuffer0=1/((iClose(0,0,i)/(-3))+(iClose(0,0,i+1)/(-6))+(iClose(0,0,i+2)/(-5))+(iClose(0,0,i+3)/3)+(iClose(0,0,i+4)/21)+(iClose(0,0,i+5)/46)+(iClose(0,0,i+6)/67)+(iClose(0,0,i+7)/74)+(iClose(0,0,i+8)/67)+(iClose(0,0,i+9)/46)+(iClose(0,0,i+10)/21)+(iClose(0,0,i+11)/3)+(iClose(0,0,i+12)/(-5))+(iClose(0,0,i+13)/(-6))+(iClose(0,0,i+14)/(-3)))/320;
//15 MA weights: -3,-6,-5, 3, 21, 46, 67, 74, 67, 46, 21, 3,-5,-6,-3 total sum is 320.
}Mrm
You are on a wrong path. The attached document contains a step-by-step formula evaluation for Spencer moving average (pages 5 to 9 - except that the way it is written it does not solve the "centering" part as the formula on Wolfram math world site, the rest is OK)
The one already posted ("Spencer moving average" indicator) is correct.
regards
MladenThanks for the pdf & wolfram links
Xard777
Since this thread is already dealing with these, let us keep them together : There is one more variation of Spencer's moving average : a 21 point moving average (previous one posted is 15 point moving average - I am using the name ("moving average") given to it at Wolfram's math world even though some are using "Spencer's filter" name) Some more information about the Spencer's 21 point moving average can be found here : Spencer's Formula -- from Wolfram MathWorld When you compare it to 15 point one it is even smoother, but, again, keep in mind that it is a centered moving average and in this one last 11 bars are a subject of change
hi mladen,
could you make an indicator that calculates the speed of the difference between 2 centered moving averages?
for the 'future' data I use in excel the same value as the last available one.
speed can be calculated as:
1. Value(x) - Value (x-1), or
2. (Value(x) / Value (x-1)) - 1
if possible, both versions would be very helpful.
this indicator is helpful in identifying cycles.
thanks.
engula
Here you go
Some explanation about the parameters. In order to allow both Spencers' filter usage, added a parameter to choose. If you set the Use21SpencersFilterto true it will calculate the 21 filter, otherwise it will calculate the 15 filter. Also, you can choose if it will use future data in calculation (with UseFutureDataForMomentumparameter) or not. And the last option is for the calculation mode : if you choose 1 for FormulaVersionToUseparameter it will calculate the first version you have asked for, otherwise it will use the second calculating mode.
PS: when using future data for calculation (UseFutureDataForMomentum set to true) it does not calculate the current value (it can not since it still does not "know" the next value that will follow). It could be avoided (the lack of the current bar value) but then the formula would be (previous-current) and not (current-future). It can be changed in the call to calculateMomentum. (line 110 of the code for the case described). Also, when in that mode, it effectively inverts the momentum when compared to the "non-future" calculation mode (here is a comparison of the "regular" and "use future" mode of 21 Spencers' filter)
And to remind again : whichever version of calculation is used, those are centered moving averages, which means that for filter 15 last 7 and for filter 21 last 10 bars can be changed (I am not using the "repaint" term since it is a natural "behavior" of centered moving averages / filters, and they have to recalculate those values in order to add a certain kind of extrapolated values in place of the values that are missing (the last half period bars) due to the centering process of the filter itself)
regards
Mladen
hi mladen,
could you make an indicator that calculates the speed of the difference between 2 centered moving averages?
for the 'future' data I use in excel the same value as the last available one.
speed can be calculated as:
1. Value(x) - Value (x-1), or
2. (Value(x) / Value (x-1)) - 1
if possible, both versions would be very helpful.
this indicator is helpful in identifying cycles.
thanks.engula
Here you go
Some explanation about the parameters. In order to allow both Spencers' filter usage, added a parameter to choose. If you set the Use21SpencersFilterto true it will calculate the 21 filter, otherwise it will calculate the 15 filter. Also, you can choose if it will use future data in calculation (with UseFutureDataForMomentumparameter) or not. And the last option is for the calculation mode : if you choose 1 for FormulaVersionToUseparameter it will calculate the first version you have asked for, otherwise it will use the second calculating mode.
PS: when using future data for calculation (UseFutureDataForMomentum set to true) it does not calculate the current value (it can not since it still does not "know" the next value that will follow). It could be avoided (the lack of the current bar value) but then the formula would be (previous-current) and not (current-future). It can be changed in the call to calculateMomentum. (line 110 of the code for the case described). Also, when in that mode, it effectively inverts the momentum when compared to the "non-future" calculation mode (here is a comparison of the "regular" and "use future" mode of 21 Spencers' filter)
And to remind again : whichever version of calculation is used, those are centered moving averages, which means that for filter 15 last 7 and for filter 21 last 10 bars can be changed (I am not using the "repaint" term since it is a natural "behavior" of centered moving averages / filters, and they have to recalculate those values in order to add a certain kind of extrapolated values in place of the values that are missing (the last half period bars) due to the centering process of the filter itself)
regards
MladenMladen, many thanks for your quick reply!
I'm afraid my request was not clear, sorry for that. I think it's much easier to code than the one you provided. I'll try to be more precise...
What I'm looking for is the following:
1. calculate CMA(x), suppose x=5:
CMA(5) = (SMA(t-2)+SMA(t-1)+SMA(t)+SMA(t+1)+SMA(t+2)) / 5
where t = last close and the 'future' values are set equal to t. this would result as:
CMA(5) = (SMA(t-2)+SMA(t-1)+SMA(t)+SMA(t)+SMA(t)) / 5
2. calculate a second CMA(y) with the same logic as above
3. calculate the difference of the 2 CMAs: DIFF = CMA(x) - CMA(y)
4. calculate the velocity of DIFF in 2 different ways:
a. VEL(DIFF(z)) = DIFF(z)-DIFF(z-1)
b. VEL(DIFF(z)) = (DIFF(z)/DIFF(z-1)) - 1
I'd like to be able to input the parameters x and y of the 2 CMAs and to choose which of the 2 velocities should be used.
Sorry again if I mislead you with my previous post and hope you can find the time to look at this again. If you need some additional info please let me know.
Thanks again!
CMO - angula
This would be it
There is no repainting since the future values are replaced with current value. Velocity in this one is calculated to the first formula (this one : VEL(DIFF(z)) = DIFF(z)-DIFF(z-1))
PS: CmaHalfPeriod2 should be less than CmaHalfPeriod1 in order to show correct velocity direction (in some ways, it reminds of MACD - similar rules : if you invert those 2 you are going to get inverted signals too). Also defualt velocity period is one, but I think that a bit longer bvalues might be bteere (see the lower example : velocity period 14)
regards
Mladen
Mladen, many thanks for your quick reply!
I'm afraid my request was not clear, sorry for that. I think it's much easier to code than the one you provided. I'll try to be more precise...
What I'm looking for is the following:
1. calculate CMA(x), suppose x=5:
CMA(5) = (SMA(t-2)+SMA(t-1)+SMA(t)+SMA(t+1)+SMA(t+2)) / 5
where t = last close and the 'future' values are set equal to t. this would result as:
CMA(5) = (SMA(t-2)+SMA(t-1)+SMA(t)+SMA(t)+SMA(t)) / 5
2. calculate a second CMA(y) with the same logic as above
3. calculate the difference of the 2 CMAs: DIFF = CMA(x) - CMA(y)
4. calculate the velocity of DIFF in 2 different ways:
a. VEL(DIFF(z)) = DIFF(z)-DIFF(z-1)
b. VEL(DIFF(z)) = (DIFF(z)/DIFF(z-1)) - 1
I'd like to be able to input the parameters x and y of the 2 CMAs and to choose which of the 2 velocities should be used.
Sorry again if I mislead you with my previous post and hope you can find the time to look at this again. If you need some additional info please let me know.
Thanks again!This would be it
There is no repainting since the future values are replaced with current value. Velocity in this one is calculated to the first formula (this one : VEL(DIFF(z)) = DIFF(z)-DIFF(z-1))
PS: CmaHalfPeriod2 should be less than CmaHalfPeriod1 in order to show correct velocity direction (in some ways, it reminds of MACD - similar rules : if you invert those 2 you are going to get inverted signals too). Also defualt velocity period is one, but I think that a bit longer bvalues might be bteere (see the lower example : velocity period 14)
regards
Mladenhi mladen, many thanks.
if you say that it doesn't repaint, then this worries me...
since it has to repaint...
this indicator should at the end look similar to the snake, but has a different algorithm behind.
it's the slope of the difference of 2 cma.
let me make an example how a cma should be calculated (unfortunately reading the code, i'm not capable to understand how it works):
assuming the last closed bar is at time t0 and we want to calculate cma(5), then:
cma(5)(t0) = [cma(5)(t-2) + cma(5)(t-1) + cma(5)(t0) + cma(5)(t+1) + cma(5)(t+2)] / 5
where: cma(5)(t0) = cma(5)(t+1) = cma(5)(t+2), so to set all future (unknown) values equal to the value of the last closed bar. this means also that every time a bar is closed, the value of cma(5) has to be recalculated.
this is why it has to be repainting.
hope my explanation was helpful (any question, pls let me know), looking forward showing you all how this indi can be of help identifying cycles!
regards