Then there's MOVING AVERAGES

Each day we compute the average stock price over the past M days ... and plot it.
We also compute the average price over the past N days ... and plot it.
When they cross we BUY ... or maybe we SELL
depending upon whether the crossing is from above or below
It might look like so:
So you play with the numbers M and N until you're happy.
Of course, a simple 200day Moving Average,
like MA = (P_{1} + P_{2} + P_{3} + ... + P_{200})/200,
gives equal weight to all Prices, even the one that occurred 200 days ago!
So, if we want to give more weight to more recent Prices, we could use a
Weighted Moving Average:
WMA = (P_{1} + 2P_{2} + 3P_{3} + ... + 200P_{200})/K
where K is a magic number (which we'll explain in a minute).
Note that we are assuming that P_{1} is the price 200 days ago and
P_{200} is the most recent Price ... and this most recent price is
multiplied by 200 so it's 200 times more significant than the 200day old Price, right?
Okay, what's K?
If all Prices are equal to, say P, we want the
weighted average to equal P as well. That means:
WMA = (P + 2P + 3P + ... + 200P)/K = P(1 + 2 + 3 + ... + 200)/K
must equal P, so K must equal (1 + 2 + 3 + ... + 200).
As you might imagine, there's a magic formula for this sum, namely:
1 + 2 + 3 + ... + 200 = 200*201/2 so that's the value for K.
In general, for an Nday moving average, we have
K = 1 + 2 + 3 + ... + N = N(N+1)/2
(I think Euler discovered this
when he was six years old. How does that make you feel?)
Our Weighted Moving Average is now:
Weighted Moving Average = WMA= 2(P_{1} + 2P_{2} + 3P_{3} + ... + N P_{N})/{N(N+1)}

Of course, nobody sez that the relative weights 1, 2, 3, ... are etched in stone. We could choose any
weights w_{1}, w_{2}, w_{3}, ... w_{N}, and get:
Weighted Moving Average = WMA = (w_{1}P_{1} + w_{2}P_{2} + w_{3}P_{3} + ... + w_{N} P_{N})/K
where K = w_{1} + w_{2} + w_{3} + ... + w_{N}
= Σ w_{k}

Note that the number K is chosen so that, in the case where all Prices
are equal, the Moving Average is equal to that Price as well.
It's time for a picture (where we use the weights 1, 2, 3, ...):
Note that the Weighted Moving Average (which emphasizes more recent
Prices) follows the stock price more closely than the Simple 20day
average.
Then there's
Exponential Moving Averages and
Moving Average Convergence/Divergence (MACD)
and ... well, you get the idea.
See also Moving Averages
Another thing ...
In order to simplify the calculation of the Weighted
Moving Average WMA (with relative weights 1, 2, 3, ... N)
we do this:
We have, at the current time period (which we'll call "Now"):
WMA(Now)= (P_{1} + 2P_{2} + 3P_{3} + ... + NP_{N})/K
and, at the next time period (where P_{N+1} is the "Next"
stock Price):
WMA(Next) = (P_{2} + 2P_{3} + 3P_{4} + ... + NP_{N+1})/K
and if we
subtract, we get:
WMA(Next)  WMA(Now) = (P_{1}  P_{2}  P_{3}  ...  P_{N} + N P_{N+1})/K
and here we recognize P_{1} + P_{2} + P_{3} + ... + P_{N}
as N times the Simple Moving Average at time period "Now" ... which we'll call MA(Now), what else?
That gives a prescription for computing our "Next" Weighted Moving Average:
WMA(Next) = WMA(Now) + { N MA(Now) + N P_{N+1}}/K
and it's time to stick in K = 2/{N(N+1)} and get:
WMA(Next)
= WMA(Now) + 2/(N+1){P_{N+1}  MA(Now)}

So, assuming you're at time period 123 (that's "Now"
and it could be 123 days or 123 weeks or ...)
and you're workin' on 26day
moving averages (so N = 26) and you have the values of
WMA(Now) and MA(Now) and the "Next" stock Price,
P_{124}, then you get the
"Next" Weighted Average like so:
WMA(Next) = WMA(Now) + 2/27 {P_{124}  MA(Now)}.
So now, having the "Next" stock Price you also compute the Simple
Moving Average of the last 26 prices, namely MA(Next),
then "Next" becomes "Now" and you start again, to compute a new "Next"
... now, ain't that right?
Okay, now we're ready for:
Exponential Moving Average(Next) = EMA(Next)
= EMA(Now) + 2/(N+1){P_{N+1}  EMA(Now)}

See the similarity? (Just replace MA by EMA)
However, it looks better written:
Exponential Moving Average(Next) = EMA(Next)
= (1  2/(N+1))EMA(Now) + 2/(N+1)P_{N+1}

where EMA(Next) appears as a weighted average of EMA(Now)
and P_{N+1}.
In fact, let's write the "weight factor" as:
so that it reads:
Exponential Moving Average(Next) = EMA(Next)
= α EMA(Now) + (1  α)P_{N+1}

Okay, so why does this give an "Exponentially Weighted Average"?
Let's pick some weight, say α < 1 (like, mebbe
α = .9, meaning 90%) and do the following:
EMA(Now) = K { P_{N} + α P_{N1}
+ α^{2} P_{N2} + ... }
where the series goes on forever ... or, at least back to the first day you start
to compute the sum(!) ... and, as usual, K is chosen so that the weighted
average of equal stock prices, say P, is just P itself. That means that
EMA(Now) = K { P + α P
+ α^{2} P + ... } must equal P, and, since
the infinite series 1 + α
+ α^{2} + ... adds up to
1/(1α) (believe me, it does), we get:
K P/(1α) = P, hence
K = (1α) and (finally!):
EMA(Now) = (1 α) { P_{N} + α P_{N1}
+ α^{2} P_{N2} + ... }

Now we see that this is definitely a weighted average, with yesterday's price
weighing in at 90% (if α = .9) and the day before
having a weight of α^{2}, or 90% of 90% (namely 81%),
and the day before that having a weight of
α^{3} or 90% of 90% of 90% (or 72.9%)
and one hundred days ago, that price has a weight
of just (0.9)^{100} = 0.00002 (or 0.002%) ... well, you get the idea, right?
Now, if we also write
EMA(Next) = (1 α) { P_{N+1} + α P_{N}
+ α^{2} P_{N1} + ... }
and compute
EMA(Next)  α EMA(Now), we get
EMA(Next)  α EMA(Now) =
(1  α)P_{N+1} (since most everything cancels out), and we get:
EMA(Next)
= α EMA(Now) + (1  α)P_{N+1}

See? It's the EMA equation we got before 'cept, now, we do
recognize it as an exponentially weighted average!
(Did I mention that the weights α,
α^{2},
α^{3}, etc. are the reason
for calling it
exponentially weighted"?)
One curious thing. For a 12day EMA, one chooses
α = 1  2/(N+1) with N = 12 and for a
26day EMA, one chooses
α = 1  2/(N+1) with N = 26, etc. even
tho' the average is certainly not an average over just 12 or 26 days,
but over all previous stock prices!
Now, we're ready for:
Moving Average Convergence/Divergence(Next) = MACD(Now)
= EMA_{12day}(Now)  EMA_{26day}(Now)

where EMA_{12day} means the 12day (N = 12)
Exponential Moving Average.
Here's MACD for a fastmoving exponential average (12day) minus
a slowmoving exponential average (26day):
Of course, y'all don't hafta use the numbers 12
and 26 used by all them thar investment gurus ...
When MACD goes positive (meaning the fast average moves above the slow),
that's a BULLish signal. When it goes negative, that's
BEARish.
VOLUMEWEIGHTED MOVING AVERAGE

There are jillions of Weighted Moving Averages; pick your weights as
the periods of oscillation of a butterfly wing and you've got yerself
another WMA. Most play with just the stock price and ignore
the volume of stock traded at that price.
If today's closing price is $16 and last month it closed at $12, then is today's
price more significant ... because it's more recent (hence more relevant)?
I don't think so, not if only ten shares traded at $16 whereas ten million
traded last month at $12. (Okay, I exaggerate, but you get
the idea, no?) That brings us to my favourite (which we'll
call VMA), not necessarily because
it gives better BUY/SELL signals, but because it makes some sense (to me,
cuz VMA_{Nday} is approximately the average price paid for each
share of stock over the past N days).
It's simple.
We take, as weights w_{1}, w_{2}, w_{3}, etc.
the volumes of stock traded at Prices P_{1}, P_{2}, P_{3}, etc.
and get:
VolumeWeighted Average = VMA = (V_{1}P_{1}
+ V_{2}P_{2} + V_{3}P_{3} + ... + V_{N} P_{N})/K
where K = V_{1} + V_{2} + V_{3} + ... + V_{N}
= Σ V_{k}

Here's a stock and the volume of trades:
The trading price in May was really important ...
look at the volume! Anyway, we plot the weighted moving average over, say
N = 100 days (why not?) and get:
I'm getting ahead of myself.
You see the stock price and the 100day VMA in a lovely
blue and also the 5day
Moving Average. (I hate to look for places where the stock price crosses some
moving average; the stock price is too finicky, too nervous,
too apt to spikethenfall, too volatile
... so we use a fast moving average, like 5day,
'cause it follows the stock price pretty closely and it's smooother, right?)
So what're the BUY/SELL signals?
Stare at the plot and decide when you'd like to BUY or SELL.
At those points, note that the VMA is a long way from the fast (5day)
average. That provides our signals:
When VMA  (5day) > A then we BUY.
When VMA  (5day) < B then we SELL.
For example, if we plot the difference VMA  (5day) we get:
OOPs! I've used the label VA for the Volume Weighted Average,
rather than VMA; sorry 'bout that.
And what're optimal choices for A and B?
(Above, I chose A = B = 1.5
at my wife's suggestion.)
And is 5 the best number of days for the fast average?
And why is 100 chosen in the VMA?
(Because there are 100 cents/dollar or 100 asparagus in my garden?)
You Decide!
One other thing:
Some people caculate the Volume Weighted Average Price after each trade,
throughout the day!
If they can buy a stock at less than this
VWAP, that's good. If they can sell stock
at a price higher than the VWAP, that's good, too.
As you might expect (since I think the volume of stock traded
shouldn't be ignored), I have for you a
Volumeweighted Exponential Moving Average which I'll call VEMA.
It's obtained as follows:
VEMA(Next) = Num(Next)/Den(Next)
where
Num(Next) = α Num(Now) +
(1  α) V_{N+1} P_{N+1}
and
Den(Next) = α Den(Now) +
(1  α) V_{N+1}

and "Num" and "Den" stand for Numerator and Denominator, respectively
and the numbers V_{N}
are the volumes of stock traded each day
and, as before, α = 1  2/(TimePeriod + 1) so, for
a 12day VEMA, we'd have α = 1  2/13 = .846
You can, of course, take VEMA_{12day}  VEMA_{26day}
to get a Volumeweighted MACD which I call VMACD (and my son calls VD).
Does it differ much from the gardenvariety MACD? Yes, if the volume of stock
trades changes a bunch, like so:
Here, the price dropped but the volume increased thereby increasing the significance of these
lower prices; when the gardenvariety MACD dropped ('cause the price dropped
so the 12day EMA dropped) the increased volume kept the VEMA from dropping
so dramatically.
Note: If the volume doesn't change from day to day, then VMACD and MACD
are identical.
I think that's enuff, for now.
Except ... uh ... I should mention the
Signal Line. You see, some
technical gurus use yet another line (curve?) called the
Signal Line
and take as BUY/SELL signals the times when MACD crosses this
Signal Line.
You get it by (are you ready for this?)
taking the 9day
Exponential Moving Average of the
MACD. In case y'all done forgot, that's got from:
EMA_{9day}(Next)
= α EMA_{9day}(Now)
+ (1  α) MACD(Next)

where α = 1  2/(9+1) = .80 and it looks like so:
Just one last thingy: formulas which look like:
A(N+1) = α A(N)
+ (1  α) P(N+1)
compute a sequence of exponentiallyweighted averages of the sequence of numbers
P(1), P(2), P(3), ...
Aah, but how to start?
Y'all kin start with A(1) = (1  α)P(1) and go from there, like so:
A(2) = α A(1) + (1  α) P(2)
which is really (1  α)[ P(2) + αP(1)]
A(3) = α A(2) + (1  α) P(3)
which is really (1  α)[ P(3) + αP(2) + α^{2}P(1) ]
A(4) = α A(3) + (1  α) P(4)
which is really (1  α)[ P(4) + αP(3) + α^{2}P(2) + α^{3}P(1)]
etc. etc.
Eventually, how you started becomes lost in the distant (hence irrelevant) past.
Okay, now we talk about stock price trends ... is it generally heading UP or DOWN?
Some like to draw a trendline connecting a series of highs (or lows) going maybe UP
or going maybe DOWN:
Trending UP: the Bulls are winning 
Trending DOWN: the Bears are winning 
As you can see, it's sort of a personal thing; you draws 'em as you see 'em.
The stock price keeps bouncing off the red line as though
it's being supported by that line ... so it's called the line of support.
Prices can't seem to break through the green line; it's
called resistance. One (presumably) waits for some sign
that the stock price has changed trends and bravely crosses either line, leaving the channel.
(The channel between
the red and the green
lines is called the ... uh ... channel.)
Here's a beauty; it's trending UP ... uh ... or is it trending DOWN?
It's called trendless
I invented the above charts to illustrate trends, but
here's a real live example:
Me? I find it difficult to identify any trend, just by
eyeballing the chart ... especially the beginning of a trend. (After it's over, it's
too late!)
Maybe there's a more analytical/technical/sophisticated method to identify trends, which
brings us to:
Directional Movement Indicator
or Directional Motion Indicator
or Directional Moving Index
or ... just plain DMI

We consider a competition between the bulls and bears. The bulls
gobble up stock
and drive the stock price to the high for the day. The bears dump their stock and
drive
the price to the low for the day. Who wins?
Each day we compute BULL points if today's high is greater than
yesterday's high.
BULL points are (today's high)  (yesterday's high)
^{*}
... or zero if the high goes DOWN.
Each day we compute BEAR points if today's low is smaller than yesterday's low.
BEAR points are (yesterday's low)  (today's low)
^{*}
... or zero if the low goes UP.
^{*} In order to be somewhat more meaningfull, we'll
divide these differences by "today's" closing price so they become percentages.
I'm not sure if Mr. Wilder (the author of DMI and RSI) did this, but we will.
Then, each day we see which points are bigger: the BULL points
or the BEAR points
(recognizing that, on some days, they may both be zero).
If the BULL points are bigger, they get awarded to the
bulls.
If the BEAR points are bigger, they get awarded to the bears.
(Get it?)
Here's the BULL and
BEAR points, for a sequence of days:
Uh ... the horizontal axis includes weekends when there were no points
... like Sep 25/26 and Oct 2/3
Note that, on Sep 24, there were both BULL and
BEAR points, but only the
BEAR points were awarded  to the bears
(cuz their points wuz bigger).
Okay, here are the points that were actually awarded (to either the bulls or the bears)
for the six month period covered by the stock price chart (above):
and, for reference, the stock chart itself:
The bulls were winning in November, eh what? (I owned CBR then!)
Okay, here's what we do ... actually, what Mr. Wilder does, 'cause DMI is his baby:
We take the sequence of awarded BULL points,
say B(1), B(2), B(3) ...
and compute the
14day Exponential Moving Average of this sequence
(Remember the EMA? Use:
EMA(n+1) = α EMA(n)+
(1α)B(n+1)
with α = 1  2/(14+1))
The resultant curve is called
+DI.
Then we take the sequence of awarded BEAR points and compute the
14day Exponential Moving Average of this sequence (remember the EMA?).
The resultant curve is called
DI.
Then we plot 'em both, like so:
and, for reference, the stock chart itself:
Notice something interesting? When the +DI
gets bigger than the DI, there's a UP trend
(the bulls are winning) and
when the DI
gets bigger than the +DI, there's a DOWN trend
(the bears are winning) and these events usually happen near the beginning of the trend!!
Of course, if we take the difference between +DI
and DI we'd get a chart that goes positive when
the former exceeds the latter (the more the bulls are ahead, the bigger this
difference would be) so we compute:
(+DI) 
(DI)
or, better still (to "normalize" things) we divide this difference by their sum, giving (finally!):
ADX = 100
{
(+DI) 
(DI)
}/
{
(+DI) +
(DI)
}

(assuming the denominator doesn't equal zero ... else just use (+DI)  (DI) and
forget my attempt to normalize)
That'd give this guy:
and, for reference, the stock chart itself:
Uh ... did I mention it was called ADX (Average Directional Indicator)?
Oh yeah ... that ritual of dividing
each of the high and low differences by the closing price, each day
(in order to get a percentage),
makes absolutely no difference to the ADX. I think that most techies just look to see when
+DI crosses DI (regardless of their values, or the "scale" one uses) and stare raptly at ADX
(whose value isn't influenced by that "divide by the closing price" ritual).
It's in the nature of the sport that bulls get very excited when the
ADX is increasing
... especially when it exceeds 50.
(I guess bears get excited when it's decreasing.)
I should mention that, if the spikes in ADX are bothersome,
then a moving average of
the ADX values will provide some smoothing.
Here's the 10day moving average:
and, for reference (have I said that before?), the stock chart itself:
Check out DI+/ (sometimes called DMI+/) and ADX on your stock at bigcharts.com.
It'll look like so:
PS#1
So, did DMI predict the 1987
C^{R}A_{S}H ?
You decide:

Note that I've called them DMI+ and DMI for a change of pace
PS#1.5
... and what does DMI say of the recent past?
You decide:

PS#2
It's been said (not by me!) that one can't use DMI on singlevalue sequences of numbers, like
Mutual Funds (that don't have daily Highs and Lows). Take a peek at these charts (where I just
made the High & Low stock prices equal to the Close ... hence a single daily value):
PS#3
Another thing: the use of the Exponential Moving Average is not the only choice one has (to
incorporate the recent stock price history). We could also use (of course!) the Volumeweighted
Moving Average. Here it is (for the CBR stock), where we're changing the names of
+DI and DI to
VDI+ and VDI and the
ADX we'll call VDX:
15day VMA of Bull & Bear Points 
VDX = 100 [(VDI+)  (VDI)] / [(VDI+) + (VDI)] 
Stock Prices 
the Volume (with the Average shown) 
Note: Volumeweighting is important if there's a large variation in the volume of trades.
Large volume in early October affects the VMA hence the VDI hence the VDX, causing it to
stay low ('cause the bears were winning) whereas the ADX rose (then fell back to
where it belonged, rejoining the VDX).
On the other hand, the high volume in midNovember (when the bulls were winning) allowed
the VDX to stay high (while the ADX fell more rapidly and even go negative for a day or two,
just after Nov 26).
Conclusion: with Volumeweighting, there's a certain amount of inertia
associated with stock prices accompanied by high volume; the VDX tends to be more sluggish
after high volume days. The effect hangs around for a while and the VDX is less temperamental,
less likely to frivolously change direction with every spike in stock price  especially
prices with low volume. That may  or may not  be a good thing.
Another note: in the Volume chart, there are blanks along
the horizontal time axis. Them's weekends!
For more on VDI and Volumeweighted EMA, see EMA.

Here we compare the current stock price, P, with the smallest and largest stock prices
over the past N days: its smallest daily Low and its largest daily High.
If these are L and H respectively, then we determine how far up the range from L
to H that the current price lies. That percentage is:
%K = 100 (P  L) / (H  L)
(You get %R = 100% when the Price equals the High over the past N days.)

As you might imagine, we plot the values of %K (which lie between 0% and 100%)
... either with or without smoothing. (Smoothing involves taking a 2 or 3day average of the
%K values). No smoothing? It's a fast stochastic.
In addition, we calculate the M day moving average of %K
... and call it %D. This might be a weighted average, such as described above.
In any case, we watch to see when %K falls below or above some magic number
(like below 20% or above 80%) ... or when it crosses %D. The chart below shows a few months
of %K (with N=10 days) and a 2day (smoothed) version and an M=5day, simple
moving average (that's %D) and some red and
green arrows at the 20% and 80% values ... meaning
SELL ... or maybe BUY ... or maybe ...

Whereas the Stochastic Oscillator compares the current closing price with the Lowest price over the previous
N days, the Williams %R determines how far down the range from H
to L that the current price lies.
%R = 100 (H  P) / (H  L)
(You get %R = 100% when the Price equals the Low over the past N days.)

Note that %K + %R = 100%
See also Williams
Once upon a time, an Italian mathematician called
Leonardo Fibonacci (while studying the population
growth in rabbits) considered the sequence of numbers: 1, 1, 2, 3, 5, 8, 13, ... where each number
is the sum of the two previous numbers (so, for example, the next number would be
13 + 8 = 21).
The numbers satisfy the equation F_{n+2} = F_{n+1} + F_{n} with
F_{1} = F_{2} = 1.
The ratio of successive numbers satisfies
F_{n+2}/F_{n+1} = 1 + 1/{F_{n+1}/F_{n}} and if we let n become
infinite we get the limiting value of this ratio, namely x which satisfies:
x = 1 + 1/x or x^{2}  x  1 = 0
which has as a solution
x = (1/2)[1 + SQRT(5)] = 1.618.
Notice that 1/x = x  1 so 1/1.618 = 0.618 (or 61.8%).
Notice that 1  1/x = 1  0.618 (or 38.2%).
The number x is called the Golden Ratio.
(See
Golden Ratios.)
An interesting note: Divide a line into two parts so as to have these Ratios:
x / 1
= (1  x) / x
then (surprise!) x = 0.618


In any case, this number has been applied to so many things that it seemed inevitable that it'd
be applied to the stock market. We'll talk about Fibonacci fans.
To see a DOWN Fibonacci fan we do this:
 Draw a line from a Maximum stock price to a subsequent Minimum.
 This gives a Trend Line ... with some magic slope.
 We draw other lines (fans?) with slopes which are 61.8% and 38.2% of the Trend Line slope.
 Where these Fibonacci fans intersect the stock price chart we get (maybe) resistance
levels or (maybe) buy & sell signals or ...
You can play with Fibonacci fans here.


Martin Zweig wrote a book, "Winning on Wall Street", where he describes (among other things) a 4% Rule.
He credits Ned Davis as the creator of this strategy.
I goes like so:
 If, on Friday, the closing price is 4% higher than the low for recent weekly closes, Buy.
 If, on Friday, the closing price is 4% lower than the high for recent weekly closes, Sell.
Of course, you may find it difficult to buy at Friday's close
You could, of course, try buying at the open, on Monday.
The intention is to identify a market bottom (so you Buy) or a top (so you Sell).
You might also want to play with the 4% ... and you may want to apply this stratgey just to a mutual or index fund (representing many stocks).
There's a spreadsheet available ... check out Zweig.
It gives a chart something like the one shown at the right.


There's also a larger and more sophisticated spreadsheet by Anthony Iannarelli. It will (among other things) search for the best percentage (as opposed to the 4%).
To download Anthony's spreadsheet, RIGHTclick here and Save Target.
A WORD OF EXPLANATION: I'm learning 'bout this technical analysis bumpf as I go along.
Each time I discover something new (and interesting) I stick it here provided I can
understand it (hence adequately describe it) ... and sometimes, somebuddy suggests a topic.
(e.g. I learned about the existence of Bollinger & RSI & MACD from my son and I invented the
"volumeweighted" stuff myself (tho' it wasn't the first time it was invented :^) and DMI was brought to my
attention by JeanClaude).
There are two (old!) spreadsheets to play with:
Bollinger bands and
Moving Averages
(RIGHTclick and Save Target or Save Link to download these .ZIPd files)
and also more tutorial
Bumpf on VMA
P.S. For other TA bumpf:
Check here.
