9.80
6 58.20
7 58.408 58.90 58.60 57.40 58.60 58.52 58.30 57.959 59.10 59.40 59.20 58.20 58.86 58.75 58.5310 61.00 59.30 59.50 59.45 58.67 59.10 58.98i 62.10 61.90 61.77 61.35 60.15 60.15 60.3012 62.00 63.20 63.73 63.15 62.75 62.37 61.5313 62.50 61.90 62.70 63.50 63.38 63.20 62.9414 63.50 63.00 62.60 63,00 63.68 63.71 63.6415 61.30 64.50 64.16 63.70 63.84 64.34 64.3816 61.70 60.10 61.23 62.05 62.25 62.69 63.36IS 17 62.00 62.10 60.36 61.10 61.66 61.87 62.3011-16 18 62.20 62.30 62.37 61.10 61.36 6171 61.86117 19 61.70 62.40 62.47 62.55 61.57 61.64 61.851s 20 61.50 61.20 61.67 — 61.95 6217 61.47 6151(1-19 21 62.40 61.30 61.10 61.35 61.61 61.85 613111-22 22 61.40 63.30 62.57 62.05 61.99 62.07 62.2011-23 23 59.90 60.40 6L67 61.75 61.57 61.61 61.7311-24 24 59.80 58.40 58.73 59.85 60.29 60.37 60.5811-26 25 59.10 59.70 58.76 58.85 59.22 59.59 59.7111-29 26 59.50 58.40 58.85 58.30 58.06 58.55 58.8711-30 27 59.10 59.90 59.17 59.10 58.56 58.20 58.48
 
THE MOVING AVERAGE
The simplest and most well-known of all smoothing techniques is called the moving aver-age (MA). Using this method, the number of elements to be averaged remains the same,but the time interval advances. Using a generalized time series as an example, Po, P1,P,,..., Pyare a sequence of prices. A moving average measured over n of these prices, ordata points, at time ¢ would be _
ProusPrati t Pine 2MA, = 4 i ne
n n
 
   
In other words, the most recent moving average calculation is the average (arithmeticmean) of the prior n data points. For example, using three points (# = 3) to generate amoving average:
MAs =P; + P2 + P3)/3MAs= (P2 +P; + Pa)/3
MA = (Pr-2 + Pra + P/3 
_and
66 TREND CALCULATIONS
 
 
TABLE 4-2 Analysis of Predictive Error for Copper
Predictive Error for an n-Day Linear RegressionSequence Price
 
    
Date @ P E(2). E38) E(4)e E(S). E(6). E(7).10-21 1 60.3010-22 2 59.3010-25 3 58.7010-26 4 57.8010-27 5 59.8010-28 6 58.2010-29 7 58.40H-01 8 58.9011-03 9 59.1011-04 to 61.0011-05 " 62.1011-08 12 62.0011-09 13 62.5011-10 4 63.50wen 15 61.301-12 16 61.70tts 7 62.001-16 18 62.2011-17 19 61.7011-18 20 61.50Weg 62.4041-22 n 61.40 1.90 11711-23 23 59.90 50 17 16711-24 24 59.80 ~1.40 1.07 49-26 25 59.10 60 -34 a2 :11-29 26 “59.50 -1.10 =70 1.44 =9511-30 w7 59.10 80 07 ~54 =90G (Standard deviation} 1.209 1.217 List 1149marca » .030 -037 027 037V (Variance) 389 406 1.260 55
     
 
If, represented a price at a specific time, the moving average would smooth the pricemovement. When more prices are used, the new price will be a smaller part of the averageand have less effect on the final value. Five successive prices form a five-day moving aver-age. When the next sequential price is added and the oldest is dropped off, the prior aver-age is changed by ' of the difference between the old and the new values. If
MAs = (Pi + P2+P3+Po+Ps)/5
MAg = (P2 + Ps + Py + Ps +Po)/5
then c = P, + P; + Ps + P; can be substituted for the common part of the moving average,solved for c, and substituted to get
MAg = MAs + (P;— Py-9)/5
This also gives a faster way to calculate a moving average. It can be seen that the moreterms in the moving average, the less effect the addition of a new term is likely to have:
MA,=MA,.1+ @:-Py-n)/n
THE MOVING AVERAGE ‘7
The selection of the proper number of terms is based on both the technical considerationof the predictive quality of the choice (measured by the error) and the need to determinePrice trends over specific time periods for commercial use. The more days or data pointsused in the moving average, the more smoothing will occur; variation lasting only a shortwhile will have less effect. There is also a danger of losing cyclic or seasonal price patternsby selecting the wrong value of n. For example, a repeating cycle of four data points 5, 8,3, 6, 9, 4, 7,..., which advances by the value 1 each complete cycle, will appear as astraight line if a moving average of 4 days is used. If there is a possibility of a cyclic or sea-sonal pattern within the data, care should be taken to select a moving average that is outof phase with the possible pattern (that is, not equal to the cycle period).
The length of the moving average must also relate to its use. A jeweler may purchasesilver each week to produce bracelets. Frequent purchases of small amounts keep the com-Pany’s cash outlay small. The purchaser can wait as long as possible while prices continueto trend downward during any one week but will buy immediately when prices turnupward. A 6-month trend cannot help his problem, because it gives a long-term answer to
a short-term issue; however, a 5-day moving average may give the trend direction withinthe jeweler’s time frame.
UserFriendly Software
Fortunately, we have reached a time when it is not necessary to perform these calculationsthe long way. Spreadsheet programs and specialized testing software provide simple toolsfor performing trend calculations as well as many other more complex functions discussed
in this book. The notation for many of the different spreadsheets and software is very sim-ilar and self-explanatory:
Function Spreadsheet Omega
Sum @sum(1ist, period)Moving average @avg(list, period)Standard deviation @std(list, period)
@summation(value, period)@average(value, period)@stddev(value, period)
What Do You Average?
The closing or daily settlement is the most common price applied to a moving average. Itis generally accepted as the true price of the day and is used by many analysts for calcula-tion of trends. But other alternatives exist. The average of the high and low prices of theday will smooth the results by preventing the maximum difference-from occurring whenthe close is also the high or low. Similarly, the closing price may be added to the high andlow, and an average of the three used as the basis for the moving average. -
Another valid component of a moving average can be other averages. For example, if -P, through P, are prices, and MA, is a 3-day mioving average, then
MA; = (Pi + P2 + P3)/3
MAg = (P2 + P3 + Py)/3
MAs = (P3 + Ps+Ps)/3and
MAS = (MA, + MAs + MAs)/3MA; is a double-smoothed moving average, which gives added weight to the center points.More on double smoothing can be found later in this chapter. Smoothing the highs andlows independently is another technique that creates a representation of the daily trading 
“68 TREND CALCULATIONS
 
range, or volatility. This has been used to identify normal and extreme moves, and will alsobe discussed in Chapter 5 (“Trend Systems”).
 
‘Types of Moving Averages
Besides varying the length of the moving average and the elements that are to be averaged,there are a great number of variations on the moving average.
An accumulative average may be used for a long-term trend. It does not satisfy ourstrict definition of a moving average, because it adds data but does not discard any; there-fore, it is cumulative. It is traditionally started at the beginning of a futures contract andcontinued until the contract expires. It may be applied to stocks after each dividend notice.Due to the accumulation of prices and the constant increase in the length of the average,the effect of the additional price at day t on the moving average will be (P, — AVG)/#, whereANG is the average of all prices from the beginning through ¢. The impact of 1 day becomesvery small toward the end of a 1-year contract, which has approximately 250 trading days.A reset accumulative average is a modification of the standard accumulative average andattempts to correct for the loss of sensitivity as the number of trading days becomes large.This alternative allows you to reset or restart the moving average whenever a new trendbegins, a significant event occurs, or at some specified time interval.
Truncated moving averages are the most common, and they are often called simplemoving averages. The most basic has already been discussed in detail. An alternate methodof calculating a daily moving average calculation is to keep the total of the past n days. Eachnew day then only requires the addition of the new value and subtraction of the oldestone. The new total is saved for the next day and is also divided by 7 to get the new movingaverage value. An interesting twist to this technique is the average-modified method, inwhich the price of the new day is added and the last moving average value is subtracted.Returning to the example of a 5-day moving average, day 6 was
MAg = MAs + (Ps ~ P)/SThis becomes,
MAg = MAs + (Ps — MA,)/5
‘The average-modified version is convenient, because only the prior maving averagevalue and the new price are necessary for each calculation. The substitution of the movingaverage value tends to smooth the results even more than a simple moving average. Its useprevents the difference (P; — P,) from becoming too extreme; it effectively cuts the possi-ble range in half and dampens the end-off impact.
‘The weighted moving average opens many possibilities. It allows the significance ofindividual or groups of data to be changed. It may restore proper value to parts of a datasample, or it may incorrectly bias the data. A weighted moving average is expressed in itsgeneral form as
> wh rai
_ WP t WP yt + WePrine eR
Wy + Wt + Wy ~ S w,
w,
This gives the weighted moving average at time fas the average of the previous n prices, eachwith its own weighting factor w, The most popular form of this technique is called front-loaded, because it gives more weight to the most recent data and reduces the significance ofthe older elements. Therefore, for the front-loaded weighted moving average (see Figure 4-1)
W,2Wz,2° Zw,
‘THE MOVING AVERAGE 6
 
‘The weighting factors w, may also be determined by regression analysis, but then they maynot necessarily be front-loaded. A common modification to front loading is called stepweighting in which each successive w; differs from the previous weighting factor w,., by afixed increment
Caw wy.)
The simplest case takes integer values for an n-day step-weighted moving average:
w,=nw,=n-1w_,=1
This gives the weighting factors the values of 5, 4, 3, 2, and J for a 5-day average. A com-puter program for calculating a linearly weighted moving average is
 
FIGURE 4-1 A comparison of moving averages.
 
63.00 +
      
2 0 © © oAccumutated
“ar
28T
PRICE (cents)
g8
oof
 
 
615
121312/61207
 
1972211/2311724)11726112911/30
rot
122
 
wiz
 
  
ory TREND CALCULATIONS
 
1 sum = .2 for I= 1 to N begin
3 M=N- 141; '4 sum = sum + M*price;
5 end;
6 — LWMA = sum/ ( N* (NH1) /2)
In line 6, the divisor (N*(N+1))/2 is the arithmetic formula for the sum of 1 + 2 +--+.Another approach would be a percentage relationship between 7, elements,
Wi =axuy;
where @ = .90; then, ws = 5, w, = 4.5, ws = 4.05, wz = 3.645, and w, = 3.2805.Prices may also be weighted in groups. If every two consecutive data elements have thesame weighting factor,
Pe + WP + W2P 2 + WsP, — 3 + + WanPr ener
Ww,2% (Uy tw, to + Waa)
 
or, grouped with n'even,
Ww = Pet Peni) + wrPra + Prag) +o + Wya(Pronea + Prone)
2X (Wit Wet + Wap)
Any number of consecutive data elements can be grouped for a step-weighted moving aver-age. Because there can be any number of combinations, there is no simple, automaticmethod for calculating anything other than a linearly weighted average, which is the func-tion @WAverage(price, length) in Omega’s Easy Language. If the purpose of weighting isto duplicate a pattern that is intrinsic to price movement, then the following sections ongeometric averages and exponential smoothing may provide better tools.
. These moving averages can also be plotted in different ways, each way having a majorimpact on their interpretation. The conventional plot places the moving average value MA,on the same vertical line as the last entry P, of the moving average. When prices have beentrending higher over the period of calculation, this will cause the value MA, to lag behind(or below) the actual prices; when prices are declining, the moving average will be abovethe prices (see Figure 4-2).
The plotted moving average can either /ead or lag the last price recorded. If it is to leadby 3 days, the value MA, is plotted on the vertical line ¢ + 3; if it is to lag by 2 days, it is plot-ted at t~ 2. In the case of leading moving averages, the analysis attempts to compensate forthe tinie delay by judging price direction using a forecast based on current rate of changeand direction. A penetration of the forecasted line by the price may be used to signal achange of direction. The lag technique may also serve the more sophisticated purpose ofphasing the moving average. A 10-day moving average, when lagged by 5 days, will be plot-ted in the middle of the actual price data. This technique will be covered later.
Comparison of Moving Average Methods
‘The comparison seen in Table 4-3 confirms that simple moving averages taken over shorterperiods identify shorter trends. The 3-day moving average trendline had 9 separate trends,while the 10-day had only 5. The 5-day average modified method was very similar to the 10-day simple moving average due to removing the average price each day. The cumulativeaverage showed the fewest trends even though it began its accumulation process only 10days prior; as time increases, this trend will become less responsive. For this short sampleinterval, the 10-day linearly weighted average was identical to the average modifiedmethod and very similar to the 10-day simple average; however, because it weights therecent data 10 times greater than the oldest, this similarity will not continue. A closer lookwill show that the trend values are very different. -
THE MOVING AVERAGE 1
 
URE 4-2 Plotting fag and lead for a 10-factors of 10,9,8,....
 
lay step-weighted moving average with weighting
—— Daily prices{tep- weighted maa.Lag plot of ma.9.9000 Lead plot of m.a.
63.00}-
   
PRICE (cents)
 
 
 
   
 
58.00 =ESELLLLISTSSCSSRREeR ss$sgswre re RST ES SESESSESSESSASSA
- DATE aTriangular Weighting
While the simple moving average or linear regression treats each price equally, exponent
smoothing, and linear step weighting puts greater weight on the ost ceeent tan there san entire area of study in which the period of the dominant cycle is the basis for determin.ing the best trend period. Triangular filtering! is a related concept that attempts to uncoverthe trend by reducing the noise on both the front and rear of the trend window, where it isexpected to have the greatest interference. Therefore, if a 20-day weighted average is used.the 10th day will have the greatest weight, while days 1 and 20 will have the smallest.
Yo implement triangular weighting, begin with the standard formula for a weightedaverage,
 
‘JJ. Payne, “A better way to smooth data,” Technical Analysis of Stocks & Commodities (October 1989). 
 
TABLE 4-3 Comparison of Moving Averages Methods*5-Day 10-Day“Simple Moving Averages pverage Cum Linearly
Price «3-Day _—“S-Day _—_—‘I0-Day Modified Average Weighted
930316 64.59930317 64.23930318 65.26930319 65.24930322 65.07930323 65.14930324 64.98930325 64.76
 
 
                                
930326 65.11
930329 65.46 65.11 65.09 64.98 78.10 65.46930330 65.94 65.50 65.25 65.12 75.67 65.07,930331 66.10 65.83 65.47 65.31 73.76 65.16930401 66.87 66.30 65.90 65.47 72.38 65.29930402 66.56 66.51 66.19 65.60 7422 65.38930405, 66.71 66.71 66.44 65.76 70.31 65.47
930406 66.19 66.49 66.49 65.87 69.49 65.51930407 66.14 66.35 66.49 65.98 68.82 65.55930408 66.64 66.32 66.45, 66.17 68.38 65.61930412 67.33 66.70 66.60 66.39 68.17 65.70930413 68.18 67.38 66.90 66.67 68.17 65.83930414 67.48 67.66 67.15 66.82 68.04 65.90930415, 67.19 67.62} 67.36 66.93 67.87 65.96
  
               
930416 66.46 67.04. $°67.33° 66.89 ETSI 65.98930419 67.20 66.95... 67.30; 66.95 67.51 66.03930420 67.62 67.09 | 67.19; 67.04 67.53 66.10930421 67.66 67.49 67.23 67.19 67.56 66.16930422 6789 67.72 67.37 = 67.37 67.62 66.22930423 69.19 68.25 67.91 67.62 67.94 66.33930426 69.68 68.92 68.41 67.86 68.29 66.44930427 6931 69.39 «68.75 67.97 68.49 6.54930428 69.11 69.04 68.13 68.61 66.62930429 69.27 6931 68.34 68.75 6671930430 68.97 69.27, 68.59 68.79 66.77.930503 69.11 69.15.23 6878 68.85 66.84930504 69.50 69.19 69.19 68.97 68.98 66.92930505 69.70 69.44 «69.31 69.17 69.13 67.00930506 69.94 67.08930507 69.11 67.13930510 67.64 67.14930511 67.75 67.16930512 67.47 67.16930513 67.50 67.17930514 68.18. 67.20 ~
       
930517 67.35930518 66.74930519 67.00930520 67.46930521 67.36930524 67.37930525 67.78 67.50 67.39 67.57 67.24930526 67.96 67.70 67.59 67.47 67.65 C2
No. Trends Tt 9 5 5 3 5
   
 
* The gray areas of the table show downtrends.
 
THE MOVING AVERAGE 3
 
where 1 is the size, or width, of the window. The weighting factors w, will increase linearlyfrom 1 to the middle of the window, at n/2, then decrease to the end at n. This has a slightlydifferent form when the period is odd or even,
w= i, for i = 1 to @intportion((n+2)/2)n-i+l, for i = @intportion((n+2)/2) + 1 ton (even values of 7)n-i, for i = @intportion((nt+2)/2) + 1 tan (odd values of m)
where, for odd values of n, the weight factor has the value 7 when i ranges from 1 to /2(rounded up using the function for the integer portion) and the value of m — / from 7/2 ton. Instead of a triangular filter, which is very precise about the middle value having thegreatest importance, we may choose a2 Gaussian filter, which weights the data in a formsimilar to a bell curve. Here, the weighting factors are more complex,
w,=10" and =3(1-2)
Pivot-Point Weighting
Too often we limit ourselves by our training. When a weighted moving average is used, itis normal to assume that all the weighting factors should be positive; however, that is nota requirement. The pivot-point moving average uses linear weights (e.g., 5, 4,...) thatbegin with a positive value and continue to decline even when they become negative.? Thismethod treats the oldest data in a manner opposite to their direction. In the following for-mula, a pivot point, where the weighting is zero, is reached about % of the way through thedata interval. For a pivot-point moving average of 11 values, the 8th data point is weightedwith 0:PPMA,(11) = (7P, + 6P; + SP, + 4P, + 3P, + 2P, + LP, + OP, — LP, - 2P, — 3P,)/22°
This technique is intended to limit the lag by front loading the prices and reducing the divi-sor of the weighting formula by the sum of the negative weighting factors. The general for-mula for an 1-day pivot-point moving average is?
PPMA,(72) = aaeD > Gi-n-1)P,
To implement this in a computer program, the following steps would be used:
 
1 sum = 0;
2 for I= 1 to N begin
3 M=N-141;
4 sum = sum + PEM]*(3*I1 ~ N - 1)55 end;
6 — PPMA = sum*(2/ (N* (N+I)))
where lines 2 through 5 calculate the sum of the prices times the weighting factor, and line6 divides that sum by the sum of the weighting factors (after multiplying the top and bot-tom of the fraction by the value 2).
The negative weighting factors reverse the impact of the price move for the oldest datapoints rather than just give them less importance. For a short interval this can cause thetrendline to be out-of-phase with prices. The application of this method should be limitedto longer-term cyclic markets, where the reflection point, at which the weighting factorbecomes zero, aligns with the cyclic turn or can be fixed at the point of the last trendchange.
? patrick E. Lafferty, “End-Point Moving Average,” Technical Analysis of Stocks & Commodities (October 1995).Don Kraska, “Letters To S&C,” Technical Analysts of Stocks & Commodities (February 1996, p. 12). 
14 TREND CALCULATIONS
 
GEOMETRIC MOVING AVERAGES
The geometric mean is a growth function that is very applicable to long-term price move-ment, introduced in Chapter 2 (“Basic Concepts”). It is especially useful calculating thecomponents of an index. The geometric mean can also be applied to the most recent npoints at time ¢ to get a geometric average similar to a moving average
G,
 
* im(PX Pra XK Pring YO = (U1 Ps)
The daily calculation is more complicated but, as shown in Chapter 2, could be rewrittenas
_ InP, tIn Py to + IN Penta
This is similar in form to the summation of.a standard moving average based on the arith-metic mean and can be written for either spreadsheet or program code as,
InG,
GA = @average(@log(price) ,n) "
Note that some software will use “log” although the calculation is actually the natural log,In. Other programs will allow the choice of @1og(value) or @1n(value). A weighted geo-metric moving average would have the form
 
Ing, = Main Pet ws I Pri + +weln Pyne. Wy + Wy + + Wy
 
S witn PieSw
The geometric moving average itself would give greater weight to smaller values withoutthe need for a discrete weighting function. In applying the technique to actual commodityprices, this distinction may not be obvious. For widely ranging values such as 1,000 and 10,the simple average is 505 and the geometric average is 10