App-Chart

 view release on metacpan or  search on metacpan

doc/chart.texi  view on Meta::CPAN

The regularized exponential moving average (REMA) by Chris Satchwell is a
variation on the EMA (@pxref{Exponential Moving Average}) designed to be
smoother but not introduce too much extra lag.  The formula can be given in a
number of forms, such as

@tex
$$ REMA = { Rp
            + \alpha \times (close - Rp)
            + \lambda \times (Rp + (Rp-Rpp))
          \over 1 + \lambda } $$
@end tex
@ifnottex
@example
       Rp + alpha*(close - Rp) + lambda*(Rp + (Rp-Rpp))
REMA = ---------------------------------------------
                 1             +      lambda
@end example
@end ifnottex
alpha = N-day smoothing per EMA @*
Rp = yesterday's REMA @*
Rpp = day before yesterday's REMA @*
@m{\lambda,Lambda} is a factor controlling the amount of ``regularization''.

This form shows how there's an @m{Rp + \alpha \times (close -
Rp),Rp+alpha*(close-Rp)} part like an EMA, and an @math{Rp+(Rp-Rpp)} part
which projects from yesterday's REMA according to whether it was rising or
falling relative to the REMA of the day before.  The two parts are averaged
with a weighting 1 for the EMA part and @m{\lambda,lambda} for the projection.

If @m{\lambda,lambda} is zero then REMA is the same as a plain EMA@.
Satchwell suggests fairly small values for @m{\lambda,lambda}, and the default
in Chart is 0.5.  John Ehlers noted that if @m{\lambda,lambda} is large REMA
becomes unstable.

In any case the result of the calculation is still an average of past prices
with a certain set of weights that progressively decrease for older data.  The
following is the weights for @math{N=15} and @m{\lambda=0.5,lambda=0.5},

@myimage{chart-rema-weights, Regularized EMA weights graph}

@subsection REMA Momentum
@anchor{REMA Momentum}
@cindex REMA Momentum
@cindex Regularized Momentum

A momentum indicator is formed from REMA as the slope of the line from
yesterday's REMA to today's.

@tex
$$ RegMom = { REMA - REMA_{prev} \over REMA_{prev} } $$
@end tex
@ifnottex
@example
         REMA - REMAprev
RegMom = ---------------
             REMAprev
@end example
@end ifnottex

This is like a Rate of Change (@pxref{Momentum and Rate of Change}), but on
just one day and as a fraction instead of a percentage.  A crossing through
zero of the RegMom is a peak or trough (and possibly just a flat spot before a
further rise or fall in the REMA line).

@subsection Additional Resources
@itemize
@item
@uref{http://www.traders.com/Documentation/FEEDbk_docs/Archive/072003/TradersTips/TradersTips.html}
-- TASC Traders' Tips, August 2003, REMA and REMA momentum formulas.
@end itemize


@c ---------------------------------------------------------------------------
@node Sine Weighted Moving Average, T3 Moving Average, Regularized Exponential Moving Average, Averages
@section Sine Weighted Moving Average
@cindex Sine weighted moving average
@cindex Sine-MA
@cindex Average, sine weighted
@cindex Moving average, sine weighted

A sine weighted moving average (Sine-MA) applies weights to each day in the
shape of the bulge in a sine curve from 0 to @m{\pi,pi}.  For an N-day average
the weightings are

@tex
$$ \sin {1 \over N+1} \pi, \;\;
   \sin {1 \over N+1} \pi, \;\; \dots, \;\;
   \sin {N \over N+1} \pi
$$
@end tex
@ifnottex
@example
     /  1      \         /  2      \             /  N      \
sin |  --- * pi |,  sin |  --- * pi |, ..., sin |  --- * pi |
     \ N+1     /         \ N+1     /             \ N+1     /
@end example
@end ifnottex

The effect is that middle prices have the greatest weight (much like the TMA,
@ref{Triangular Moving Average}).  The graph below shows the weights for
@math{N=10}.  In Chart SWMA is under ``Low Priority'' in the indicator lists.

@myimage{chart-sine-weights, Sine weights graph}


@c ---------------------------------------------------------------------------
@node T3 Moving Average, Triangular Moving Average, Sine Weighted Moving Average, Averages
@section T3 Moving Average
@cindex T3 moving average

The T3 moving average by Tim Tillson is a triple smoothed combination of the
DEMA (@pxref{Double and Triple Exponential Moving Average}) and a plain EMA
(@pxref{Exponential Moving Average}).

A given ``volume factor'' V (default 0.7) controls how much of the DEMA is
used.  The factor ranges from 0 which gives a plain EMA, up to 1 which gives a
full DEMA@.  Values in between are a combination.  The formula for this
``generalized DEMA'' is

@tex
$$ GD(N,v) = (1-v) \times EMA[N] + v \times DEMA[N] $$

doc/chart.texi  view on Meta::CPAN

@end example
@end ifnottex

When the close is at the high the factor is @math{+1} and the full volume is
added in, when the close is at the low the factor is @math{-1} and the full
volume is subtracted.  In between is in proportion, so for instance a close at
75% of the range would be a factor @math{+0.5}, or a close midway would be a
factor 0 for no change to the Acc/Dist.

The starting point (ie.@: the zero point) for the running total is arbitrary.
In Chart it's merely the segment of data first displayed.

The name accumulation/distribution comes from the idea that during
accumulation buyers are in control and the price will be bid up through the
day, or will make a recovery after being sold down, in any case finishing near
the high.  Vice versa for distribution.

Acc/Dist is somewhat similar to On-Balance Volume (@pxref{On-Balance Volume}).
But Acc/Dist looks at close within that day's range, whereas OBV looks just at
close-to-close up or down.  An Acc/Dist calculation within an N-day window can
be made too, see @ref{Chaikin Money Flow}.


@c ---------------------------------------------------------------------------
@node Accumulative Swing Index, Aroon, Accumulation/Distribution, Indicators
@section Accumulative Swing Index
@cindex Accumulative swing index
@cindex ASI
@cindex Index, accumulative swing

@cindex Wilder, J. Welles
The accumulative swing index (ASI) by J.@: Welles Wilder forms a cumulative
total of certain swing index values which are a tricky weighted combination of
close-to-close, open-to-close, and high-to-low range amounts each day.

The close-to-close dominates the swing index, so the ASI broadly follows the
shape of the price curve.  Wilder recommended looking for trend lines and
breakouts in the ASI to confirm price trend lines.

The starting point (ie.@: the zero point) for the running total is arbitrary.
In Chart it's merely the segment of data first displayed.  Wilder's
calculation applied a scaling factor based on the daily limit move, but this
is not done in Chart.  The shape of the resulting curve is not changed by
that.

@anchor{Swing Index}The raw swing index values can be viewed with the ``Swing
Index'' (which is under ``Low Priority'' in the indicator lists because it's
of little direct use).


@c ---------------------------------------------------------------------------
@node Aroon, Average True Range, Accumulative Swing Index, Indicators
@section Aroon
@cindex Aroon

@cindex Chande, Tushar
The Aroon indicator by Tushar Chande shows the length of time since the
highest or lowest close among the past N days' closes.  There are three lines:
Aroon Up for the high, Aroon Down for the low, and the Aroon Oscillator.

Aroon Up and Down are both expressed as percentages 0 to 100.  If today is a
new N-day high then Aroon Up is 100, and for each day that passes (without a
fresh N-day high) it drops by 100/N, down to 0 for no new highs in the past N
days.  Conversely for Aroon Down for new N-day lows.

The Aroon Oscillator is simply the difference between the Up and Down lines,

@tex
$$ AroonOsc = AroonUp - AroonDown $$
@end tex
@ifnottex
@example
AroonOsc = AroonUp - AroonDown
@end example
@end ifnottex

In Chart the Up line is drawn in green, the down in red, and the oscillator in
white.


@c ---------------------------------------------------------------------------
@node Average True Range, Centre of Gravity Oscillator, Aroon, Indicators
@section Average True Range
@cindex Average true range
@cindex ATR

@cindex True range
@cindex Wilder, J. Welles
Average true range (ATR) by J.@: Welles Wilder is the daily ``true range''
values (@pxref{True Range}) smoothed by an N-period exponential moving average
(@pxref{Exponential Moving Average}).

@tex
$$ ATR = EMA[N] \, of \, True \, Range $$
@end tex
@ifnottex
@example
ATR = EMA[N] of True Range
@end example
@end ifnottex

The default smoothing period is 14 days, as recommended by Wilder.  The period
is always by Wilder's reckoning of EMA smoothing period (@pxref{Wilder EMA
period}).

The idea behind ATR is that when traders are enthusiastic, either in an
uptrend or downtrend, the range will be higher as the stock or commodity is
bid up or sold down through the day.  A lesser range suggests waning interest.

When a data source doesn't provide high/low values (some indices for
instance), then just close-to-close changes are used.  This may be of limited
use.

@cindex Normalized ATR
@anchor{Normalized ATR}
@subsection Normalized ATR

@cindex Forman, John
The normalized ATR by John Forman
(@uref{http://www.theessentialsoftrading.com}) expresses the ATR as a
percentage of the current closing price.  This makes it possible to compare
ATR values over long periods where a share price level (and hence the typical
daily ranges) have changed greatly.

@tex
$$ NATR = 100 \times { ATR \over close } $$
@end tex
@ifnottex
@example
              ATR
NATR = 100 * -----
             close
@end example
@end ifnottex


@c ---------------------------------------------------------------------------
@node Centre of Gravity Oscillator, Chaikin Money Flow, Average True Range, Indicators
@section Centre of Gravity Oscillator
@cindex Centre of gravity oscillator
@cindex CG
@cindex COG

@uref{http://www.mesasoftware.com/technicalpapers.htm} @*
@uref{http://www.mesasoftware.com/Papers/The%20CG%20Oscillator.pdf}

@cindex Ehlers, John
The Centre of Gravity (CG) oscillator by John Ehlers is a comparison of recent
prices against older prices within a given past N days.

Prices from those N days are imagined as weights placed on a beam, equally
spaced, and the CG oscillator is then the balance point or centre of gravity
along that beam.
@c FIXME:
@c  The prices used are the midpoint of each day's high/low.
If @ms{p,1} is today's price, @ms{p,2} yesterday's, etc, then the formula is

@tex
$$ CG = - { 1 \times p_1 + 2 \times p_2 + \cdots N \times p_N
            \over p_1 + p_2 \cdots p_N } $$
@end tex
@ifnottex
@example
       1*p[1] + 2*p[2] + ... + N*p[N]
CG = - ------------------------------
        p[1] +   p[2] + ... +   p[N]
@end example
@end ifnottex

The ``@math{-}'' sign puts the CG on a scale of @math{-N} at the oldest end,
up to @math{-1} at the newest prices end.  But those extremes are not reached,
instead CG hovers around the midpoint @math{-(N-1)/2}.  The scale is not
important, only the shape of the curve, which rises if recent prices are
higher, and falls if recent prices are lower.

Ehlers suggests looking at a past 10 days, and that's the default.  He notes
that if N is very small the CG becomes quite noisy, and that if N is large it
tends to become very unresponsive.

@subsection Additional Resources

doc/chart.texi  view on Meta::CPAN


The indicator is calculated as the sum of 14-period and 11-period ROC values
(@pxref{Momentum and Rate of Change}), smoothed with a 10-period WMA
(@pxref{Weighted Moving Average}).  Adding the two ROCs has the effect of
averaging their values.

@tex
$$ Coppock = WMA[10] \; of \; (ROC[14] + ROC[11]) $$
@end tex
@ifnottex
@example
Coppock = WMA[10] of (ROC[14] + ROC[11])
@end example
@end ifnottex

Coppock designed the indicator for use on a monthly time scale, which can be
viewed in Chart with @key{Ctrl-M} (@pxref{Main Window}).  In other timebases
(days or weeks) Chart uses the same 14, 11 and 10 periods, which may or may
not be useful, since months were what Coppock intended.

The indicator generates a buy signal for long-term investors when it's below
zero and turns upwards from a trough.  The nature of the calculation means
this will be well after the low in prices, the signal is meant to indicate a
good rally has been established.


@c ---------------------------------------------------------------------------
@node Detrended Price Oscillator, Directional Movement Index, Coppock Curve, Indicators
@section Detrended Price Oscillator
@cindex Detrended price oscillator
@cindex DPO
@cindex Oscillator, detrended price

The detrended price oscillator (DPO) aims to eliminate an intermediate or long
term trend and show variations around that trend.  It's calculated on a given
N days using today's close and a past simple moving average (@pxref{Simple
Moving Average}),

@tex
$$ DPO = close - SMA\ over\ N\ days,\ as\ at\ {N\over2}+1\ days\ ago $$
@end tex
@ifnottex
@example
DPO = close - SMA over N days, as at N/2+1 days ago
@end example
@end ifnottex

This is somewhat similar to momentum (@pxref{Momentum and Rate of Change}),
but instead of taking the close N days ago, an average (the SMA) of N days
surrounding that point is used.


@c ---------------------------------------------------------------------------
@node Directional Movement Index, Ease of Movement, Detrended Price Oscillator, Indicators
@section Directional Movement Index
@cindex Directional movement index
@cindex DMI

@cindex Wilder, J. Welles
The directional movement index by J.@: Welles Wilder expresses so-called
directional movement, from high to high, or low to low, as a percentage of
true range (@pxref{True Range}).

When today's high is above yesterday's high, the increase is upwards
directional movement, written DM+.  If today's high is not above yesterday's
then DM+ is zero.  Conversely when today's low is less than yesterday's low
the decrease is downward directional movement, written DM-.  Again if today's
low is not below yesterday's then DM- is zero.  Both DM+ and DM- are positive
numbers, the ``+'' and ``-'' signs just refer to the direction of the
movement.

On an ``inside day'' where today's trading range is entirely within
yesterday's both DM+ and DM- are zero.  On an ``outside day'' where today's
trading goes both above and below yesterday's range, only the larger of DM+
and DM- is used and the other is set to zero.

The two DM+ and DM- series are each smoothed with an N-day exponential moving
average (@pxref{Exponential Moving Average}) and expressed as a percentage of
average true range (@pxref{Average True Range}).  The ATR uses the same N-day
EMA smoothing.  Two lines are formed, the upwards directional index DI+ and
downwards directional index DI-.

@tex
$$ DI+ = 100 \times { EMA[N] \, of \, DM+ \over ATR[N] } \;\;\;\;\;
   DI- = 100 \times { EMA[N] \, of \, DM- \over ATR[N] } $$
@end tex
@ifnottex
@example
            EMA[N] of DM+                 EMA[N] of DM+
DI+ = 100 * -------------     DI+ = 100 * -------------
                ATR[N]                        ATR[N]
@end example
@end ifnottex

In Chart, DI+ is drawn in green (for upwards) and DI- is drawn in red (for
downwards).

The smoothing N is by Wilder's reckoning of EMA smoothing period (as discussed
in @ref{Exponential Moving Average}), the default is the 14 he recommended.

An extreme of 100 is approached on DI+ when each day trades entirely above
yesterday's range (eg. runaway gaps), and then closes at the high of the day.
This is rather rare, usually there's some pullbacks.  Essentially DM+ counts
just the advance, the true range in the denominator counts the backtracking
too.  For DI-, an extreme of 100 is approached similarly when each day trades
entirely lower the previous, and closes at its low.

@cindex Average directional index
@cindex ADX
@anchor{Average Directional Index}
@subsection Average Directional Index

The average directional index (ADX) combines DI+ and DI-, expressing their
difference (ignoring the sign) as a percentage of the total, forming a single
line ranging 0 to 100,

@tex
$$ ADX = 100 \times { |DI+ - DI-| \over DI+ + DI- } $$
@end tex
@ifnottex
@example
            abs(DI+ - DI-)
ADX = 100 * --------------
              DI+ + DI-
@end example
@end ifnottex


@c ---------------------------------------------------------------------------
@node Ease of Movement, Elder Bull/Bear Power, Directional Movement Index, Indicators
@section Ease of Movement
@cindex Ease of movement
@cindex Movement, Ease of

@cindex Arms, Richard
The ease of movement indicator by Richard Arms shows a ratio of price
movements over volume.  Big moves on light volume mean easy movement through
price levels, small moves and/or heavier volume means difficult movement.

@tex
$$ Ease = { midpoint_{today} - midpoint_{yesterday} \over box\,ratio } $$
@end tex
@ifnottex
@example
       midpoint[today] - midpoint[yesterday]
Ease = -------------------------------------
                  box ratio
@end example
@end ifnottex

The midpoint is the middle of the day's trading range,
ie. @math{(high+low)/2}.  The box ratio is volume over trading range, giving
the amount of volume required to move by one price tick, on the day.  Volume
is taken in millions, to bring the scale up (with no effect on the shape).

@tex
$$ box\,ratio = { volume_{today} \over high_{today} - low_{today} } $$
@end tex
@ifnottex
@example
                 volume[today]
box ratio = ------------------------
            high[today] - low[today]
@end example
@end ifnottex

Ease of movement is smoothed with an exponential moving average
(@pxref{Exponential Moving Average}), with default 14 periods.  The raw daily
values can be seen, if desired, by setting the average to 1 day.


@c ---------------------------------------------------------------------------
@node Elder Bull/Bear Power, Fisher Transform, Ease of Movement, Indicators
@section Elder Bull/Bear Power

doc/chart.texi  view on Meta::CPAN

@end ifnottex

The effect of the logarithm is to make ``smoothed'' values near 0 remain near
there, but values near 1 and @math{-1} grow greatly, thus highlighting
extremities.  A ``smoothed'' value of exactly @m{\pm 1, +/-1} would transform
to @m{\pm\inf, +/-infinity}, so a clamp of 0.999 is applied, effectively
limiting the final result to about @math{@pm{}7.5}.

@subsection Additional Resources

@itemize
@item
@uref{http://www.linnsoft.com/tour/techind/fish.htm} -- sample Nasdaq 100
symbol @samp{QQQ} from August 2002.  (For Chart use Yahoo symbol @samp{^IXIC}
to get that data).
@end itemize


@c ---------------------------------------------------------------------------
@node Force Index, Forecast Oscillator, Fisher Transform, Indicators
@section Force Index
@cindex Elder force index
@cindex Force index
@cindex Index, force
@cindex EFI
@cindex %F

@cindex Elder, Alexander
The force index by Dr.@: Alexander Elder shows daily close-to-close changes
multiplied by the volume traded, so that moves on greater volume are given
more significance.  The raw @m{change \times volume, change*volume} values are
smoothed slightly with a 2-day EMA (@pxref{Exponential Moving Average}), so
the formula is simply

@tex
$$ Force\,Index = EMA[2] \; of \; \left( volume \times (close - prev\,close)\right) $$
@end tex
@ifnottex
@example
Force Index = EMA[2] of (volume * (close - prev close))
@end example
@end ifnottex

An increasing force index indicates strong interest in an upward move, when it
falls back either price or volume or both have declined suggesting waning
interest.  Conversely for a negative and falling force index on the downside.
The smoothing period for the EMA is configurable.


@c ---------------------------------------------------------------------------
@node Forecast Oscillator, Gopalakrishnan Range Index, Force Index, Indicators
@section Forecast Oscillator
@cindex Forecast oscillator
@cindex Oscillator, forecast
@cindex FOSC
@cindex %F

@cindex Chande, Tushar
The %F forecast oscillator by Tushar Chande shows deviation between today's
closing price and an N-day linear regression forecast (@pxref{Linear
Regression}) of that close.  The deviation is expressed as a percentage of the
close, so the formula is

@tex
$$ \%F = { close - forecast \over close } \times 100 $$
$$ forecast = linear \; regression \; of \; previous \; N days,
              \; at \; today $$
@end tex
@ifnottex
@example
     close - forecast
%F = ---------------- * 100
          close

forecast = linear regression of previous N days, at today
@end example
@end ifnottex

The N days prices for the linear regression start from yesterday's close, and
the forecast value is the line extended out to today.  This forecast line is
like the EPMA (@pxref{Endpoint Moving Average}), but going out one day
further.  Chande suggests using a 5 day regression for short term trading, and
that's the default in Chart.


@c ---------------------------------------------------------------------------
@node Gopalakrishnan Range Index, Intraday Momentum Index, Forecast Oscillator, Indicators
@section Gopalakrishnan Range Index
@cindex Gopalakrishnan range index
@cindex Index, Gopalakrishnan range
@cindex GAPO

@cindex Gopalakrishnan, Jayanthi
The Gopalakrishnan Range Index (GAPO) by Jayanthi Gopalakrishnan quantifies
the variability in a stock, based on the logarithm of the trading range over
an N-day period (default 5 days).

@tex
$$ GAPO = { log(high_{Ndays} - low_{Ndays}]) \over log N } $$
@end tex
@ifnottex
@example
       log(high[Ndays] - low[Ndays])
GAPO = -----------------------------
                  log(N)
@end example
@end ifnottex

The idea is to identify markets which are more erratic than others.  It will
be noted though that there's no scaling to the overall price level.  In Chart
GAPO is  under ``Low Priority'' in the indicator lists.


@c ---------------------------------------------------------------------------
@node Intraday Momentum Index, Klinger Volume Oscillator, Gopalakrishnan Range Index, Indicators
@section Intraday Momentum Index
@cindex Intraday momentum index
@cindex Index, Intraday momentum
@cindex IMI

@cindex Chande, Tushar
The intraday momentum index (IMI) by Tushar Chande expresses upward
open-to-close movement in the past N days as percentage of total open-to-close
movement (up and down).

@tex
$$ IMI = { Sum[N]\;of\; \max(close-open, 0)
     \over Sum[N]\;of\; |close-open| } $$
@end tex
@ifnottex
@example
      Sum[N] of max(close-open, 0)
IMI = ----------------------------
        Sum[N] of abs(close-open)
@end example
@end ifnottex

This is like an RSI (@pxref{Relative Strength Index}) but on open-to-close
movement and with a simple moving average.

The use of open-to-close is also similar to the way QStick
(@pxref{QStick}) shows proportions of black and white candlesticks, with IMI
scaling according to the total real-body height in the past N days.


@c ---------------------------------------------------------------------------
@node Klinger Volume Oscillator, MACD, Intraday Momentum Index, Indicators
@section Klinger Volume Oscillator
@cindex Klinger volume oscillator
@cindex KVO
@cindex KO
@cindex Oscillator, Klinger volume

@cindex Klinger, Stephen J.
The Klinger volume oscillator (KVO) by Stephen J.@: Klinger is based on
cumulative volume, with volume added or subtracted according to the direction
of typical price and weighted by a certain daily range calculation.

A trend direction is determined from today and yesterday's ``typical prices''
(which are @math{(high+low+close)/3}),

@tex
$$ trend = \left\{ \matrix{
   1 & \mathop{\rm if} \; TP_{today}  >  TP_{yesterday} \cr
  -1 & \mathop{\rm if} \; TP_{today} \le TP_{yesterday} \cr
} \right. $$
@end tex
@ifnottex
@example
trend = /  1 if  TP[today] >  TP[yesterday]
        \ -1 if  TP[today] <= TP[yesterday]
@end example
@end ifnottex

A daily measurement @math{DM = high-low} is calculated and then a cumulative
measurement formed (cumulative while the trend direction is the same),

@tex
$$ CM = \left\{ \matrix{
  CM_{yesterday} + DM_{today}
                 & \mathop{\rm if} \; trend_{today} = trend_{yesterday} \cr
  DM_{yesterday} + DM_{today}
                 & \mathop{\rm if} \; trend_{today} \ne trend_{yesterday} \cr

doc/chart.texi  view on Meta::CPAN


@c ---------------------------------------------------------------------------
@node MASS Index, Momentum and Rate of Change, MACD, Indicators
@section MASS Index
@cindex MASS index
@cindex Index, MASS

@cindex Dorsey, Donald
The MASS index by Donald Dorsey is based on daily trading range.  Each day's
range high to low is calculated and those values are smoothed with a 9-day EMA
(@pxref{Exponential Moving Average}).  A ratio of that value with a second EMA
smoothing is then taken, and the past 25 days of those ratios added up.

@tex
$$ MASS = Sum[25] \; of \; { EMA[9] \; of \; high-low
                      \over EMAofEMA[9] \; of \; high-low } $$
@end tex
@ifnottex
@example
                    EMA[9] of high-low
MASS = Sum[25] of -----------------------
                  EMAofEMA[9] of high-low
@end example
@end ifnottex

The EMA and the EMA of EMA are normally quite close, making their ratio
usually about 1 and hence the sum formed is usually close to 25.  The most
significant pattern Dorsey looked for was a ``reversal bulge'' where the index
goes above 27 then falls back below 26.5, indicating a widening of daily
trading range and suggesting a reversal in price is likely.

@cindex EMA of EMA
@cindex Double exponential moving average
@cindex Average, double exponential
@cindex Moving average, double exponential
@anchor{EMA of EMA}
@section EMA of EMA

Applying an EMA a second time gives a quite different result from a plain
EMA@.  It's still a weighted average of recent prices, but whereas a plain EMA
is dominated by the most recent prices, a double EMA spreads more broadly, and
the latest few days' influence is in fact smaller than the peak weights (at
about N/2 days back).  The following graph shows the weights for @math{N=10}.

@myimage{chart-ema-2-weights, EMA of EMA weights graph}

The twice-smoothed EMA is also available directly as a moving average option,
under ``Low Priority'' in the indicator lists, to see its effect on prices or
on an oscillator.


@c ---------------------------------------------------------------------------
@node Momentum and Rate of Change, Money Flow Index, MASS Index, Indicators
@section Momentum
@cindex Momentum
@cindex Rate of change
@cindex ROC

Momentum and rate of change show a difference between today's close and the
close N days ago.  Momentum is the difference as a price amount (positive or
negative), rate of change scales it to a percentage increase or decrease from
that N-day ago close.  This scaling is an advantage if comparing past times
when prices levels were much higher or lower than now.  If @ms{p,1} is today,
@ms{p,2} yesterday, etc, then

@tex
$$ Momentum = p_1 - p_{N+1} $$
$$ ROC = 100 \; {p_1 - p_{N+1} \over p_{N+1}} $$
@end tex
@ifnottex
@example
Momentum = p[1] - p[N+1]

            p[1] - p[N+1]
ROC = 100 * -------------
               p[N+1]
@end example
@end ifnottex

It will be noticed that momentum is the difference between an N-day simple
moving average (@pxref{Simple Moving Average}) for today and yesterday, with a
scale factor N, ie.@:

@tex
$$ {Momentum \over N} = SMA_{today} - SMA_{yesterday} $$
@end tex
@ifnottex
@example
Momentum
-------- = SMA[today] - SMA[yesterday]
   N
@end example
@end ifnottex

This is the slope of the SMA line (price change per day) at that point.
Momentum crosses up through zero when SMA makes a peak, or down through zero
when SMA makes a trough.  The TRIX indicator (@pxref{TRIX}) does a similar
thing with a triple exponential moving average.

@subsection Additional Resources

@itemize
@item
@uref{http://trader.online.pl/MSZ/e-w-Chandes_Trendscore.html} -- Formula and
sample on Polish WIG20 from 2000.
@end itemize


@c ---------------------------------------------------------------------------
@node Money Flow Index, On-Balance Volume, Momentum and Rate of Change, Indicators
@section Money Flow Index
@cindex Money Flow Index
@cindex MFI
@cindex Index, money flow

The Money Flow Index (MFI) ranges from 0 to 100 showing dollar volume
(referred to as ``money flow'') on up days as a percentage of total up and
down days, in a given past N days.

The calculation is as follows.  A ``typical price'' is formed from the average
of high, low and close.  If high/low figures are not available then Chart just
uses the close,

@tex
$$ typical\ price = {high + low + close \over 3} $$
@end tex
@ifnottex
@example
                high + low + close
typical price = ------------------
                        3
@end example
@end ifnottex

``Money flow'' on a given day is typical price multiplied by volume.  This is
the money that flowed, ie. an approximation to the dollar volume traded.

@tex
$$ money\ flow = typical\ price \times volume $$
@end tex
@ifnottex
@example
money flow = typical price * volume
@end example
@end ifnottex

Across the N-day period two totals are formed.  ``Positive money flow'' is the
money flow on days where the typical price is higher the previous day's
typical price, and ``negative money flow'' when below.  Days when typical
price is unchanged are ignored.  The MFI is then

@tex
$$ MFI = 100 \times {positive\ money\ flow \over
               positive\ money\ flow + negative\ money\ flow} $$
@end tex
@ifnottex
@example
                      positive money flow
MFI = 100 * -----------------------------------------
            positive money flow + negative money flow
@end example
@end ifnottex

Generally an MFI level of 80 is considered overbought, and 20 considered
oversold.  Those levels are shown as shown as dashed lines.

MFI is similar to RSI (@pxref{Relative Strength Index}) in its construction
and use.  Both are looking at up days versus totalled up and down days, but
the RSI scales by price change amounts where MFI scales on dollar volume (or
an approximation to that).

It should be noted ``money flow'' refers to dollar volume, ie. the total value
of shares traded.  Sometimes finance commentators speak of money ``flowing
into'' a stock, but that expression only means buyers are enthusiastic.
Obviously there's never any net money in or out, because for every buyer
there's a seller of the same amount.

doc/chart.texi  view on Meta::CPAN

                 \  - v1   if p1 > p2
@end example
@end ifnottex

The starting point (ie.@: the zero point) for the running total is arbitrary.
In Chart it's merely the segment of data first displayed.

See also @ref{Price and Volume Trend}, and @ref{Accumulation/Distribution},
which accumulate volume in similar ways.


@c ---------------------------------------------------------------------------
@node Negative Volume Index, Polarized Fractal Efficiency, On-Balance Volume, Indicators
@section Negative Volume Index
@cindex Negative volume index
@cindex NVI
@cindex Index, negative volume

@cindex Fosback, Norman
The Negative Volume Index (NVI) and Positive Volume Index (PVI) by Norman
Fosback (@uref{http://www.fosback.com}) track price changes according to
changes in volume.  The NVI tracks closing price changes that occur on days
with lower volume than yesterday, and the PVI conversely tracks those with
higher volume than yesterday.

@tex
$$ NVI = NVI_{prev} \times \left\{ \matrix{
  close \over close_{prev} & \mathop{\rm if} \; vol < vol_{prev} \cr
  1                        & \mathop{\rm if} \; vol \ge vol_{prev} \cr
} \right. $$
@end tex
@ifnottex
@example
                   /   close
                  |  -----------    if vol < vol[prev]
NVI = NVI[prev] * |  close[prev]
                  |
                   \     1          if vol >= vol[prev]

@end example
@end ifnottex

@tex
$$ PVI = PVI_{prev} \times \left\{ \matrix{
  close \over close_{prev} & \mathop{\rm if} \; vol > vol_{prev} \cr
  1                        & \mathop{\rm if} \; vol \le vol_{prev} \cr
} \right. $$
@end tex
@ifnottex
@example
                   /   close
                  |  -----------    if vol > vol[prev]
PVI = PVI[prev] * |  close[prev]
                  |
                   \     1          if vol <= vol[prev]

@end example
@end ifnottex

The fraction @m{close/close_{prev}, close/close[prev]} means that the indices
follow percentage daily changes in the closing prices, but only changes on the
selected lower or higher volume days are used.  The starting point for the
changes is arbitrary, only the shape of the resulting line matters.  In Chart
the start is 100 for the first data portion displayed.

The principle behind the NVI is that on high volume days an uninformed crowd
is dominating, whereas on quieter days ``smart money'' is establishing
positions.  Fosback holds there's a 95% probability of a bull market when the
NVI rises above its one-year moving average.
@c FIXME   Such an average can be viewed in
@c Chart by selecting an SMA (@pxref{Simple Moving Average}) of 260 days (one
@c year's worth of weekdays).


@c ---------------------------------------------------------------------------
@node Polarized Fractal Efficiency, Pretty Good Oscillator, Negative Volume Index, Indicators
@section Polarized Fractal Efficiency
@cindex Polarized fractal efficiency
@cindex PFE
@cindex Fractal, polarized efficiency indicator

The Polarized Fractal Efficiency indicator by Hans Hannula shows how
efficient, meaning how much like a straight line, the price movement has been
over the past N days.

The net distance travelled over the past N days is expressed as a percentage
of the total of each day's distance travelled.  Distance is measured in
two-dimensions, like a ruler on the plotted graph.  Rise (or fall) is
expressed as a percentage, and each day counts as 1 unit across.  So the
formula, on closing prices @ms{p,1} (today) to @ms{p,N} is

@tex
$$ PFE = { \mathop{\rm Hypot} (N-1, \; \mathop{\rm Pchg}(p_1,p_N))
       \over { \mathop{\rm Hypot} (1, \; \mathop{\rm Pchg}(p_1,p_2))
             + \cdots
             + \mathop{\rm Hypot} (1, \; \mathop{\rm Pchg}(p_{N-1},p_N)) }} $$
$$ \mathop{\rm Sign}(x) = 1 \; if \; X>0; \; or \; -1 \; if \; X<0 $$
$$ \mathop{\rm Pchg}(new,old) = 100 \times { new - old \over old } $$
$$ \mathop{\rm Hypot}(x,y) = \sqrt{x^2 + y^2} $$
@end tex
@ifnottex
@example
                   Sign(p1-pN) * Hypot(N-1, Pchg(p1,pN))
PFE = 100 * -------------------------------------------------------
            Hypot(1, Pchg(p1,p2)) + ... + Hypot(1, Pchg(p[N-1],pN))

Sign(X) = 1 if X>0, or -1 if X<0

                      new - old
Pchg(new,old) = 100 * ---------
                         old

Hypot(x,y) = sqrt (x^2 + y^2)
@end example
@end ifnottex

Here ``Pchg'' is a percentage change up or down from ``new'' to ``old'' price,
and ``Hypot'' is the distance (the hypotenuse) for a move of X horizontally
and Y vertically.  ``Sign'' means that PFE is positive or negative according
to whether the change over the past N days is up or down.

At the extremes of 100 or -100, price movement is at maximum efficiency, with
the past N days making a perfectly straight line.  An almost straight line is
generally very close to 100 too.  A midpoint of 0 means there's been no net
change over the past N days.

Hannula looked at price changes over 10 day period (horizontal distance of 9),
and this is the default in Chart.  A smoothing parameter is provided too; it
applies an exponential moving average (@pxref{Exponential Moving Average}) to
the PFE@.  The default is 5 days smoothing, a value of 0 means no smoothing
(to see the raw values).

@subsection Additional Resources
@itemize
@item
@uref{http://www.traderslog.com/polarized-fractal-efficiency.htm} -- sample
chart of IBM, year not shown but data is 2002.
@item
@uref{http://transcripts.fxstreet.com/2005/09/polarized_fract.html} --
presentation on PFE by Erik Long.
@end itemize


@c ---------------------------------------------------------------------------
@node Pretty Good Oscillator, Price and Volume Trend, Polarized Fractal Efficiency, Indicators
@section Pretty Good Oscillator
@cindex Pretty good oscillator
@cindex PGO
@cindex Oscillator, pretty good

The ``Pretty Good Oscillator'' (PGO) by Mark Johnson measures the distance of
the current close from its N-day simple moving average (@pxref{Simple Moving
Average}), expressed in terms of an average true range (@pxref{Average True
Range}) over a similar period.

@tex
$$ PGO = { close - SMA[N]\,of\,close \over EMA[N] of true range }$$
@end tex
@ifnottex
@example
      close - SMA[N] of closes
PGO = ------------------------
        EMA[N] of true range
@end example
@end ifnottex

So for instance a PGO value of +2.5 would mean the current close is 2.5
average days' range above the SMA.

Johnson's approach was to use it as a breakout system for longer term trades.
If the PGO rises above 3.0 then go long, or below -3.0 then go short, and in
both cases exit on returning to zero (which is a close back at the SMA).

@subsection Additional Resources
@itemize
@item
@uref{http://trader.online.pl/MSZ/e-w-Pretty_Good_Oscillator.html} -- formula,
and sample chart of Cisco (@samp{CSCO}) from 2003.
@end itemize


@c ---------------------------------------------------------------------------
@node Price and Volume Trend, QStick, Pretty Good Oscillator, Indicators
@section Price and Volume Trend
@cindex Price and volume trend
@cindex PVT
@cindex Volume, price trend

Price and Volume Trend (PVT) is a running total of daily volume, with each
day's volume added or subtracted according to the percentage change in the
today's closing price over yesterday's.

@tex
$$ PVT = PVT_{prev} + volume \times
  { close_{today} - close_{prev} \over close_{prev} } $$
@end tex
@ifnottex
@example
                         close[today] - close[yesterday]
PVT = PVTprev + volume * -------------------------------
                                 close[yesterday]
@end example
@end ifnottex

The starting point (ie.@: the zero point) for the running total is arbitrary.
In Chart it's merely the segment of data first displayed.

PVT is similar to On-balance volume (@pxref{On-Balance Volume}), but
accumulating a portion of the volume.  And see also
@ref{Accumulation/Distribution}, which also accumulates volume.


@c ---------------------------------------------------------------------------
@node QStick, R-Squared Index, Price and Volume Trend, Indicators
@section QStick
@cindex QStick

The QStick indicator shows the dominance of black (down) or white (up)
candlesticks, which are red and green in Chart, as represented by the average
open to close change for each of past N days.

@tex
$$ QStick = (close_1 - open_1) + \cdots + (close_N - open_N) \over N $$
@end tex
@ifnottex
@example
         close[1]-open[1] + ... + close[N]-open[N]
QStick = -----------------------------------------
                             N
@end example
@end ifnottex

Days which are up have positive amounts for @math{close-open}, days which are
down have negative amounts.  In adding them up they cancel out until the
dominance of one over the other results.


@c ---------------------------------------------------------------------------
@node R-Squared Index, RAVI, QStick, Indicators
@section R-Squared Index
@cindex R-squared index
@cindex Index, R-Squared

@cindex Chande, Tushar
@cindex Kroll, Stanley
@cindex Correlation coefficient
@cindex Coefficient, correlation
@cindex Coefficient of determination
The R-squared indicator by Tushar Chande and Stanley Kroll is a measure of how
closely the past N days resemble a straight line, ie.@: a trend.  It
calculates what is called in statistics the @dfn{coefficient of determination}
of the prices versus a straight line.  This coefficient is written @math{r^2},
hence the name of the indicator.

For reference, the formulas are as follows, where X values are the closing
prices and Y values are a straight line 1,2,@dots{},N@.  Variance is the
square of standard deviation (@pxref{Standard Deviation}).

@tex
$$ r^2 = { (\mathop{Covariance} X,Y)^2
           \over (\mathop{Variance} X) (\mathop{Variance} Y) } $$
$$ \mathop{Covariance} X,Y = \mathop{Mean} (XY)
                             - (\mathop{Mean} X) (\mathop{Mean} Y) $$
$$ \mathop{Variance} X = \mathop{Mean} (X^2) - (\mathop{Mean} X)^2 $$
@end tex
@ifnottex
@example
         (Covariance X,Y)^2
r^2 = -----------------------
      Variance X * Variance Y

Covariance X,Y = Mean (X*Y) - (Mean X) * (Mean Y)

Variance X = Mean(X^2) - (Mean X)^2
@end example
@end ifnottex

The R-squared indicator ranges from 0 meaning no apparent correlation to the
straight line, up to 1 for perfect correlation.  The slope of the closing
prices line doesn't matter, nor does the absolute price level, only how well
they make a straight line.

Chande and Kroll suggested using a 14-day period, and that's the default in
Chart.
@c FIXME
@c   They also described a 14-day simple moving average (@pxref{Simple
@c Moving Average}) on the raw values, and that can be shown in Chart the same as
@c any average on an indicator (@pxref{View Style}).


@c ---------------------------------------------------------------------------
@node RAVI, Relative Strength Index, R-Squared Index, Indicators
@section RAVI
@cindex RAVI

RAVI is a simple indicator showing whether a stock is trending.  It calculates
the percentage difference between current prices and older prices.  Current
prices are represented by a short SMA and the longer time frame by a long SMA
(@pxref{Simple Moving Average}).  The defaults are 7 days and 65 days.

@tex
$$ RAVI = 100 \times { | SMA[short] - SMA[long] | \over SMA[long] }$$
@end tex
@ifnottex
@example
             abs (SMA[short] - SMA[long])
RAVI = 100 * ----------------------------
                      SMA[long]
@end example
@end ifnottex


@c ---------------------------------------------------------------------------
@node Relative Strength Index, Relative Volatility Index, RAVI, Indicators
@section Relative Strength Index
@cindex Relative strength index
@cindex RSI
@cindex Index, relative strength

@cindex Wilder, J. Welles
The Relative Strength Index (RSI) by J.@: Welles Wilder compares average
upward close-to-close movement against all close-to-close movement, each
smoothed by an EMA (@pxref{Exponential Moving Average}).

For each day an upward or downward movement is calculated.  On an up day

@tex
$$ U = close_{today} - close_{yesterday} $$
$$ D = 0 $$
@end tex
@ifnottex
@example
U = close[today] - close[yesterday]
D = 0
@end example
@end ifnottex

or on a down day as follows (notice D is a positive amount),

@tex
$$ U = 0 $$
$$ D = close_{yesterday} - close_{today} $$
@end tex
@ifnottex
@example
U = 0
D = close[yesterday] - close[today]
@end example
@end ifnottex

The sequence of U values over time is averaged with an EMA
(@pxref{Exponential Moving Average}) and likewise the D values.  The
ratio is the ``relative strength'',

@tex
$$ RS = { EMA[N] \, of \, U \over EMA[N] \, of \, D } $$
@end tex

doc/chart.texi  view on Meta::CPAN

which is which.


@c ---------------------------------------------------------------------------
@node Random Walk Index, Stochastics, Relative Volatility Index, Indicators
@section Random Walk Index
@cindex Random walk index
@cindex Index, random walk
@cindex RWI

The random walk index (RWI) by E.@: Michael Poulos is a measure of how much
price ranges over N days differ from what would be expected by a random walk
(randomly going up and down).  A bigger than expected range suggests a trend.

The index is in two parts, an RWI high which looks at upward movement and an
RWI low for downward movement.  In Chart RWI high is shown in green, and RWI
low in red.  The RWI high looks at terms like

@tex
$$ { High[today] - Low[K] \over Average TR [K] } \times { 1 \over \sqrt K } $$
@end tex
@ifnottex
@example
High[today] - Low[K]     1
-------------------- * ------
   Average TR [K]      sqrt(K)
@end example
@end ifnottex

which is the move from the low K days ago up to today's high, scaled by an
average of the true range (TR, @pxref{True Range}).  Such terms are calculated
for each number of days 2, 3, etc, up to the given RWI parameter N, and the
maximum is the RWI@.  The first term for instance is today's high less
yesterday's low, compared to a two-day average of the true range (yesterday's
true range and the day before's).  RWI low is similar, but using @math{High[K]
- Low[today]} for the movement down from past high to today's low.

The factor @m{\sqrt K, sqrt(K)} compares the movement to a random walk.  If a
random walk has a 50% chance of going up by one, or a 50% chance of going down
by one, then it can be shown that on average the distance travelled after K
steps is @m{\sqrt K, sqrt(K)}.  So the formula compares observed distance in
average day's steps compared to the @m{\sqrt K, sqrt(K)} steps which would be
the expected move if it were random.  Thus 1 is when movement is apparently
random, and higher or lower if some apparently non-random trend or lack of
trend (respectively) appears to be present.


@c ---------------------------------------------------------------------------
@node Stochastics, TD Range Expansion Index, Random Walk Index, Indicators
@section Stochastics
@cindex Stochastics

@cindex Lane, George
Stochastics are an oscillator and signal line described by George Lane based
on each day's close within the total trading range of past N days.  This
should not be confused with stochastic processes etc in mathematics, the two
are unrelated.

@cindex %K stochastic
The %K line is the close position within the past N-days trading range
(highest high to lowest low) expressed as a percentage 0 to 100.

@tex
$$ \%K = 100 \times {{close - Nday\;low} \over Nday\;high - Nday\;low } $$
@end tex
@ifnottex
@example
             close - Nday low
%K = 100 * --------------------
           Nday high - Nday low
@end example
@end ifnottex

@cindex %D stochastic
An extreme of 0 is reached for a close at the day's low which is also a new
N-day low.  Likewise 100 for a close at the day's high and a new N-day high.
A signal line %D is added by smoothing %K with a simple moving average
(@pxref{Simple Moving Average}).

@tex
$$ \%D = SMA[D] \; of \; \%K $$
@end tex
@ifnottex
@example
%D = SMA[D] of %K
@end example
@end ifnottex

The default periods in chart are 14 days for %K, and 3 days smoothing for %D.
The %K line is drawn in red and the %D line in green.

@cindex Fast stochastics
@cindex Slow stochastics
%K and %D just described are called the ``fast'' stochastics.  Corresponding
``slow'' stochastics are formed by smoothing %K with a simple moving average,
and calculating %D from that smoothed series.  The extra smoothing is the
``slow days'' parameter in Chart.  The default is 0 for no slowing, a value of
3 is often used.

Incidentally, a value of 1 for the slowing is the same as no slowing, because
a 1-period SMA of course doesn't change the data.


@c ---------------------------------------------------------------------------
@node TD Range Expansion Index, Trend Intensity Index, Stochastics, Indicators
@section TD Range Expansion Index
@cindex TD range expansion index
@cindex Range expansion index
@cindex TDREI

@cindex DeMark, Tom
The range expansion index by Tom DeMark is designed to identify price
exhaustion which may be the end of a move up or down.

The calculation is somewhat similar to an RSI (@pxref{Relative Strength
Index}) but looks at 2-day changes in the daily high and daily low values and
smooths with a 5-day SMA (@pxref{Simple Moving Average}).  Changes are ignored
if the current day in not either within or covering price action from 5 or 6
days ago.  That test effectively holds the indicator around zero while prices
are making breakaway runs.

DeMark regarded values above @math{+45} or below @math{-45} as overbought or
oversold.  Such a reading maintained for up to five days suggests a reversal,
except that if it remains there for 6 or more days then the signal may be
unreliable and trading should be avoided.


@c ---------------------------------------------------------------------------
@node Trend Intensity Index, Trendscore, TD Range Expansion Index, Indicators
@section Trend Intensity Index
@cindex Trend intensity index
@cindex TII

@cindex Pee, M. H.
The trend intensity index (TII) by M.@: H.@: Pee measures the strength of a
trend, by looking at what proportion of the past 30 days prices have been
above or below the level of today's 60-day simple moving average
(@pxref{Simple Moving Average}).

The 60-day average is as of today, not its past values at each of
those past 30 days.  For each day the deviation @math{close-avg} is
taken.  Positive amounts are up deviations, and negative amounts have
the sign discarded and are down deviations.

@tex
$$ up = \left\{
 \matrix{ close - average & \mathop{\rm if} \; close > average \cr
                        0 & otherwise \hfill \cr
} \right. $$
$$ down = \left\{
 \matrix{ average - close & \mathop{\rm if} \; average > close \cr
                        0 & otherwise \hfill \cr
} \right. $$
@end tex
@ifnottex
@example
up   = /  close - average   if close > average
       \        0           otherwise

down = /  average - close   if average < close
       \        0           otherwise
@end example
@end ifnottex

The percentage of the total up amounts out of total up and down amounts is
then the trend intensity index,

@tex
$$ RVIorig = 100 \times { total \; up
                  \over   total \; up + total \; down } $$
@end tex
@ifnottex
@example
                  total up
TDI = 100 * ---------------------
            total up + total down
@end example
@end ifnottex

The extreme of 100 occurs when all closes in the past 30 days have been above
today's 60-day moving average level, and conversely the extreme of 0 when all
below that level.

Visually the index is like looking at the area under the graph of prices.  The
area above a horizontal line at today's 60-day moving average is the up
amounts, the area below it is the down amounts, and the index is the fraction
of the up out of the total.

Pee recommended entering trades when levels of 80 on the upside or 20 on the
downside are reached.  Lines are shown in Chart at those levels, as is 50
which is a neutral level.

The 60 and 30 days are configurable (@pxref{View Style}).  Any values are
accepted, but it probably doesn't make much sense to have the MA period (60)
shorter than the deviations period (30).  Certainly it makes no sense to have
the two equal, because the up deviations are then always exactly 50% of the
total.


@c ---------------------------------------------------------------------------
@node Trendscore, True Strength Index, Trend Intensity Index, Indicators
@section Trendscore
@cindex Trendscore

@cindex Chande, Tushar
Trendscore by Tushare Chande@footnote{@iquot{Rating Trend Strength}, Technical
Analysis of Stocks and Commodities magazine, 11:9 (382-386)} rates the
strength of a trend.  The calculation is quite simple, today's close is
compared to each close at 11 through 20 days ago and scored @math{+1} for each
it's above and @math{-1} if below.

@tex
$$ Trendscore = \left\{
  \matrix{
    if\,close \ge close[11]\; then\; +1\; else \;-1 \cr
    +\, if\,close \ge close[12]\; then\; +1\; else \;-1 \cr
    \cdots \cr
    +\, if\,close \ge close[20]\; then\; +1\; else \;-1 \cr
} \right. $$

$$ Trendscore = 100 \times { TripleEMA[today] - TripleEMA[yesterday]
                       \over TripleEMA[yesterday] } $$
@end tex
@ifnottex
@example

doc/chart.texi  view on Meta::CPAN

@end example
@end ifnottex

The result is a rating between @math{+10} or @math{-10} for how many of those
past days the current close is above.  The high of @math{+10} is when above
all those past prices, or @math{-10} when below them all.  In a good trend up
or down those extremes are often reached.


@c ---------------------------------------------------------------------------
@node True Strength Index, TRIX, Trendscore, Indicators
@section True Strength Index
@cindex True strength index
@cindex Index, True strength
@cindex TSI

@cindex Blau, William
The true strength index (TSI) by William Blau@footnote{@iquot{The True
Strength Index}, Technical Analysis of Stocks and Commodities magazine,
November 1991, and @iquot{Trading With the True Strength Index}, May 1992.} is
variation of the RSI (@pxref{Relative Strength Index}) using two EMAs to
smooth (@pxref{Exponential Moving Average}), and a scale @math{-100} to
@math{+100}.

@tex
$$ TSI = 100 \times { EMA[13]\; of\; EMA[25]\; of\; (close - prevclose )
                \over EMA[13]\; of\; EMA[25]\; of\; \left| close - prevclose \right| } $$
@end tex
@ifnottex
@example
            EMA[13] of EMA[25] of   (close - prevclose)
TSI = 100 * --------------------------------------------
            EMA[13] of EMA[25] of  abs(close - prevclose)
@end example
@end ifnottex

The TSI ranges from @math{-100} up to @math{+100} with positive values
representing upward momentum and negative values downward momentum.  Extreme
values can be interpreted as overbought and oversold, as per the ordinary RSI.

The two EMA periods are parameters in Chart.  If you set one of them to 1 then
you get a plain RSI, though with a period by the usual reckoning whereas the
RSI is in Wilder's style (@pxref{Wilder EMA period}), so for instance a TSI
27,1 is equivalent to an RSI 14.

See @ref{EMA of EMA} for the effect of two EMAs.  In general it leads to less
weighting on the most recent data (the close-to-close differences in this
case) than a single EMA.

See also CMO (@pxref{Chande Momentum Oscillator}) using another different
moving average for an RSI.


@c ---------------------------------------------------------------------------
@node TRIX, Twiggs Money Flow, True Strength Index, Indicators
@section TRIX
@cindex TRIX

@cindex Hutson, Jack
TRIX by Jack Hutson shows the slope of a triple-smoothed N-day exponential
moving average of closing prices.  The slope is calculated as a percentage
change between today and yesterday's triple smoothed EMA values.

@tex
$$ TRIX = 100 \times { EMAofEMAofEMA[today] - EMAofEMAofEMA[yesterday]
                       \over EMAofEMAofEMA[yesterday] } $$
@end tex
@ifnottex
@example
             EMAofEMAofEMA[today] - EMAofEMAofEMA[yesterday]
TRIX = 100 * ---------------------------------------
                    EMAofEMAofEMA[yesterday]
@end example
@end ifnottex

A positive TRIX means the triple EMA is rising, suggesting a steady uptrend,
in the same way any rising moving average does.  Conversely a negative value
means the triple EMA is falling, suggesting a downtrend.  A cross through zero
is a peak or trough in the triple EMA and may suggest a trend change.  Chart
draws a line at the zero level.

@cindex EMA of EMA of EMA
@cindex Triple exponential moving average
@cindex Average, triple exponential
@cindex Moving average, triple exponential
@anchor{EMA of EMA of EMA}
@section EMA of EMA of EMA

A triple smoothed EMA is prices smoothed with an EMA then those values
smoothed again with another EMA and finally a third time with a further EMA
(all of the same given period).

The result is quite different from a plain EMA@.  It's still a weighted
average of recent prices, but whereas a plain EMA is dominated by the most
recent prices, a triple EMA spreads much more broadly, and the latest few
days' influence is in fact smaller than the peak weights (at about N-days
back).  The following graph shows the weights for @math{N=10}.

@myimage{chart-ema-3-weights, EMA of EMA of EMA weights graph}

An EMA of EMA of EMA can also be viewed directly, in the upper prices window.
This can be used to see the effect its smoothing has, and may help for
adjusting the period N to get a desired smoothness versus responsiveness.
Note the N-day period is set separately for the two windows.


@c ---------------------------------------------------------------------------
@node Twiggs Money Flow, Ulcer Index, TRIX, Indicators
@section Twiggs Money Flow
@cindex Twiggs money flow
@cindex Money flow, Twiggs
@cindex Index, Twiggs money flow

@uref{http://www.incrediblecharts.com/technical/twiggs_money_flow.htm}

@cindex Twiggs, Colin
The Twiggs money flow index by Colin Twiggs is a variation of the Chaikin
money flow index (@pxref{Chaikin Money Flow}) using true range so as to
include gap moves, and using EMA smoothing (@pxref{Exponential Moving
Average}) to avoid jumps when a high volume day drops out of the calculation.
The formula is

@tex
$$
Twiggs\,MF = { {EMA[N] \,of\;\; volume *
          \left( 2 {{close - truelow} \over {truehigh - truelow}} - 1 \right) }
               \over EMA[N] \,of\;\; volume } $$
$$ truehigh = \max (high, prevclose) $$
$$ truelow  = \min (low, prevclose) $$
@end tex
@ifnottex
@example
                                /      close - truelow       \
            EMA[N] of  volume * | 2 * ------------------ - 1 |
                                \     truehigh - truelow     /
Twiggs MF = --------------------------------------------------
                  EMA[N] of  volume

truehigh = max (high, prevclose)
truelow  = min (low,  prevclose)
@end example
@end ifnottex

The default EMA period is 21 days, and the period is reckoned by J.@: Welles
Wilder's method (@pxref{Exponential Moving Average}).


@c ---------------------------------------------------------------------------
@node Ulcer Index, Ultimate Oscillator, Twiggs Money Flow, Indicators
@section Ulcer Index
@cindex Ulcer index
@cindex Index, Ulcer

@uref{http://www.tangotools.com/ui/ui.htm}

@cindex Martin, Peter
The Ulcer Index by Peter Martin is a measure of downside volatility.  For a
given N-day period the closing prices are considered from oldest to newest and
for each close a retracement percentage is calculated, relative to the highest
close so far.

@tex
$$ R_i = 100 \times { price_i - maxprice\,so\,far \over maxprice\,so\,far } $$
@end tex
@ifnottex
@example
       price[i] - maxprice so far
R[i] = --------------------------
           maxprice so far
@end example
@end ifnottex

@cindex Quadratic mean
@cindex Mean, quadratic
So for instance a price $5.00 falling back to $4.50 is a -10% retracement.
These are averaged with a quadratic mean, which has the effect of emphasising
large drawdowns, but incorporating all into the result.

@tex
$$ Ulcer = \sqrt { R_1^2 + R_2^2 + \cdots R_N^2 \over N } $$
@end tex
@ifnottex
@example
              / R[1]^2 + R[2]^2 + ... + R[N]^2 \
Ulcer = sqrt |  ------------------------------  |
              \              N                 /
@end example
@end ifnottex

The index can be calculated over the kind of period one might hold an
investment to calculate a measure of the ulcer-producing drawdowns suffered
during that period.


@c ---------------------------------------------------------------------------
@node Ultimate Oscillator, Vertical Horizontal Filter, Ulcer Index, Indicators
@section Ultimate Oscillator
@cindex Ultimate oscillator

@cindex Williams, Larry
The Ultimate Oscillator by Larry Williams is based on buying pressure as a
proportion of true range over recent periods, with the past 7 days, 14
days and 28 days combined together.

The calculation starts with ``buying pressure'', which is the amount by which
the close is above the ``true low'' on a given day.  The true low is the
lesser of the given day's trading low, and the previous close.

@tex
$$ bp = close - \min (low, prev\,close) $$
@end tex
@ifnottex
@example
bp = close - min (low, prev close)
@end example
@end ifnottex

The true range (the same as in @ref{True Range}) is the difference between the
``true high'' and the true low above.  The true high is the greater of the
given day's trading high, and the previous close.

@tex
$$ tr = \max (high, prev\,close) - \min (low, prev\,close) $$
@end tex
@ifnottex
@example
tr = max (high, prev close) - min (low, prev close)
@end example
@end ifnottex

The total buying pressure over the past 7 days is expressed as a fraction of
the total true range over that period.  If @ms{bp,1} is today, @ms{bp,2}
yesterday, etc then

@tex
$$ avg_7 = {bp_1 + bp_2 + \cdots + bp_7 \over tr_1 + tr_2 + \cdots + tr_7 } $$
@end tex
@ifnottex
@example
       bp1 + bp2 + ... + bp7
avg7 = ---------------------
       tr1 + tr2 + ... + tr7
@end example
@end ifnottex

The same is done for the past 14 days and past 28 days and the resulting three
values combined in proportions 4:2:1, and expressed as a percentage.

@tex
$$ UltOsc = 100 \times {4 \times avg_7 + 2 \times avg_{14} + avg_{28}
                        \over 4 + 2 + 1 } $$
@end tex
@ifnottex
@example
                4 * avg7 + 2 * avg14 + avg28
UltOsc = 100 *  ----------------------------
                         4 + 2 + 1
@end example
@end ifnottex

The oscillator ranges from 0 to 100 and is interpreted in similar ways to
other oscillators, with extremes indicating overbought or oversold conditions,
and bullish or bearish divergence when new lows or highs fail to be made.
Williams recommended levels of 70 and 30 for overbought or oversold and those
are drawn by Chart.


@c ---------------------------------------------------------------------------
@node Vertical Horizontal Filter, Volatility Ratio, Ultimate Oscillator, Indicators
@section Vertical Horizontal Filter
@cindex Vertical horizontal filter
@cindex VHF
@cindex Filter, vertical horizontal

@cindex White, Adam
The vertical horizontal filter (VHF) by Adam White expresses the range of
closing prices as a fraction of total close-to-close movement over a given
N-day period.

@tex
$$ VHF = { highest\,close - lowest\,close
     \over total \, of \, each \, |close - prev\,close| }
$$
@end tex
@ifnottex
@example
          highest close - lowest close
VHF = -------------------------------------
      total of each abs(close - prev close)
@end example
@end ifnottex

This ratio ranges from 0 to 1.  The extreme of 1 means all close-to-close
movement was in one direction, so they added up to the full range.  A usual
value is somewhere in the middle, reflecting a mixture of advances and
retreats that occur even in a strong market.


@c ---------------------------------------------------------------------------
@node Volatility Ratio, Williams %R, Vertical Horizontal Filter, Indicators
@section Volatility Ratio
@cindex Volatility ratio
@cindex Ratio, volatility
@cindex VOLR

@cindex Schwager, Jack
The volatility ratio by Jack Schwager expresses the latest day's trading range

doc/chart.texi  view on Meta::CPAN

@item
%R rises above -95% or -85%.
@end itemize

or conversely to sell an overbought

@itemize @bullet
@item
%R reaches 0%.
@item
Five trading days pass since 0% was last reached
@item
%R falls below -5% or -15%.
@end itemize


@c ---------------------------------------------------------------------------
@node Williams Accumulation/Distribution, Zig Zag Indicator, Williams %R, Indicators
@section Williams Accumulation/Distribution
@cindex Williams accumulation/distribution
@cindex Accumulation/distribution, Williams
@cindex Index, Williams accumulation/distribution

@cindex Williams, Larry
The Williams Accumulation/Distribution index by Larry Williams forms a running
total of ``buying pressure'' on up days, or ``selling pressure'' on down days.

@tex
$$ WAD = WAD_{prev} + \left\{
  \matrix{
    (close - true\,low)  & \mathop{\rm if} \; close > prev\,close \cr
    0                    & \mathop{\rm if} \; close = prev\,close \cr
    (close - true\,high) & \mathop{\rm if} \; close < prev\,close \cr
} \right. $$
@end tex
@ifnottex
@example
                   / (close - true low)   if close > prev close
WAD = WAD[prev] + |  0                    if close = prev close
                   \ (close - true high)  if close > prev close
@end example
@end ifnottex

Buying pressure is represented by how far the close is above the true low
(which is the lesser of today's low or yesterday's close).  Selling pressure
is represented by how far the close is below the true high (which is the
greater of today's high or yesterday's close).  Notice the difference ``close
- true high'' is negative, so on down days WAD decreases.

The starting point (ie.@: the zero point) for the running total is arbitrary.
In Chart it's merely the segment of data first displayed.


@c ---------------------------------------------------------------------------
@node Zig Zag Indicator,  , Williams Accumulation/Distribution, Indicators
@section Zig Zag Indicator
@cindex Zig zag indicator
@cindex Indicator, zig zag

The zig zag indicator is a simple way to ignore retracements less than a given
X percentage.

When prices are rising, a line is drawn up from the previous low to the latest
high.  Pullbacks smaller than the given X% are ignored.  The trend is only
considered to have turned down when a point X% below that latest high is
penetrated.  Then a down line is drawn, it in turn continuing until a reversal
of more than X% above the last lowe occurs.  The result is a kind of zig zag,
ignoring small moves, small according to the X%.

For the last line segment, at the right of the chart, the line is drawn to the
high (or low) then horizontally to the edge of the screen.  The horizontal
part means there hasn't yet been a retracement of X% from that level shown.

@subsection Additional Resources
@itemize
@item
@uref{http://stockcharts.com/education/IndicatorAnalysis/indic_ZigZag.html} --
sample chart of @samp{HPQ} from 1999/2000.
@end itemize


@c ---------------------------------------------------------------------------
@node Common Calculations, Other Indicator Packages, Indicators, Top
@chapter Common Calculations
@cindex Common calculations

The following are algorithms and calculations shared among various indicators
and averages.

@menu
* Linear Regression::
* Standard Deviation::
* True Range::
@end menu


@c ---------------------------------------------------------------------------
@node Linear Regression, Standard Deviation, Common Calculations, Common Calculations
@section Linear Regression
@cindex Linear regression
@cindex Least squares, line

The ``least squares'' or ``linear regression'' algorithm produces a best
fitting straight line through the middle of a set of N data points
@m{x_1@comma{}y_1@comma{} ...@comma{} x_N@comma{}y_N, x1@comma{}y1@comma{}
...@comma{} xN@comma{}yN}.  In Chart this means a set of prices Y, and dates X
(with non-trading days collapsed out).

For a possible fitted line @m{L(X)=a+bX,L(X)= a + b*X}, the vertical distance
from the line to each point is squared, and a total deviation formed.

@tex
$$ SumSquares = (y_1 - L(x_1))^2 + \cdots + (y_N - L(x_N))^2 $$
@end tex
@ifnottex
@example
SumSquares = (y1 - L(x1))^2 + ... + (yN - L(xN))^2
@end example
@end ifnottex

The line parameters @math{a} and @math{b} are then chosen to make SumSquares



( run in 0.595 second using v1.01-cache-2.11-cpan-39bf76dae61 )