App-Chart

 view release on metacpan or  search on metacpan

doc/chart.texi  view on Meta::CPAN


@tex
$$ EMA_{today} = \alpha \times close + (1-\alpha) \times EMA_{yesterday} $$
@end tex
@ifnottex
@example
EMA[today] = alpha * close + (1-alpha) * EMA[yesterday]
@end example
@end ifnottex

The formula can also be written as follows, showing how the average moves
towards today's close by an @alph{} fraction of the distance from the old EMA
to the new close.

@tex
$$ EMA_{today} = EMA_{yesterday} + \alpha \times (close - EMA_{yesterday}) $$
@end tex
@ifnottex
@example
EMA[today] = EMA[yesterday] + alpha * (close + EMA[yesterday])
@end example

doc/chart.texi  view on Meta::CPAN

@c
@c  or the same on the EMA[yesterday] term
@c
@c      f = 1-1/W
@c
@c  so
@c      1-2/(N+1) = 1-1/W
@c      2/(N+1) = 1/W
@c      W = (N+1)/2      or N = 2W-1
@c
This is the same as the formula above, just a different @math{f} factor.  When
Wilder gives ``W'' days, the equivalent ``N'' above is @m{2W-1,2*W-1}, so say
14 becomes 27.  This is also sometimes called a ``modified moving average''.

In the indicators designed by Wilder, Chart uses his reckoning, so that for
instance a 14-day RSI is entered at 14.  This applies to ATR, DMI (and ADX)
and RSI (@pxref{Average True Range}, @ref{Directional Movement Index}, and
@ref{Relative Strength Index}).


@c ---------------------------------------------------------------------------

doc/chart.texi  view on Meta::CPAN

@cindex Weighted moving average
@cindex WMA
@cindex Average, weighted
@cindex Moving average, weighted

An N-day weighted moving average is an average of today's close and preceding
closes, with weighting factor N for today, @math{N-1} for yesterday,
@math{N-2} for the day before, etc.  The influence of past data thereby
decreases with its age, down to nothing beyond N days.

The formula is as follows, with @ms{p,1} for today's closing price, @ms{p,2}
yesterday's, etc.

@tex
$$ WMA = { { N p_1 + (N-1) p_2 + (N-2) p_3 + \cdots + 2 p_{N-1} + p_N }
           \over { N + (N-1) + (N-2) + \cdots + 2 + 1 } }
$$
@end tex
@ifnottex
@example
      N * p1 + (N-1) * p2 + (N-2) * p3 + ... + 2 * p[N-1] + pN

doc/chart.texi  view on Meta::CPAN


The endpoint moving average (EPMA) establishes an average price by fitting a
least squares straight line (@pxref{Linear Regression}) through the past N
days closing prices and taking the endpoint of the line (ie.@: the line as at
the last day) as the average.

This calculation goes by a number of other names, including least squares
moving average (LSQMA), moving linear regression, and time series forecast
(TSF).  Joe Sharp's ``modified moving average'' is the same thing too.

The formula ends up being a straightforward weighted average of past N prices,
with weights going from @m{2N-1,2*N-1} down to @math{-N+2}.  This is easily
derived from the least squares formulas, but just looking at the weightings
the connection to least squares is not at all obvious.  If @ms{p,1} is today's
close, @ms{p,2} yesterdays, etc, then

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

doc/chart.texi  view on Meta::CPAN

the halves don't overlap but add up to make the overall N day range.

The FRAMA alpha factor and the fractal dimension value are available in the
lower indicator window, to see where they're big or small, under ``Low
Priority'' near the end of the indicators lists.

@subsection Additional Resources
@itemize
@item
@uref{http://www.traders.com/Documentation/FEEDbk_docs/Archive/102005/TradersTips/TradersTips.html}
-- TASC Oct 2005 Traders' Tips various formulas [possibly gone].
@end itemize


@c ---------------------------------------------------------------------------
@node Guppy Multiple Moving Average, Hull Moving Average, Fractal Adaptive Moving Average, Averages
@section Guppy Multiple Moving Average
@cindex Guppy multiple moving average
@cindex GMMA
@cindex Average, Guppy multiple
@cindex Moving average, Guppy multiple

doc/chart.texi  view on Meta::CPAN

@section Regularized Exponential Moving Average
@cindex Regularized exponential moving average
@cindex REMA
@cindex Average, regularized exponential
@cindex Moving average, regularized exponential
@cindex Exponential moving average, regularized

@cindex Satchwell, Chris
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

doc/chart.texi  view on Meta::CPAN


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

doc/chart.texi  view on Meta::CPAN

@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] $$
@end tex
@ifnottex
@example
GD(N,v) = (1-v)*EMA[N] + v*DEMA[N]
@end example
@end ifnottex

doc/chart.texi  view on Meta::CPAN

@node Zero-Lag Exponential Moving Average,  , Volume Weighted Moving Average, Averages
@section Zero-Lag Exponential Moving Average
@cindex zero-lag exponential moving average
@cindex Average, zero-lag exponential
@cindex Moving average, zero-lag exponential
@cindex ZLEMA

The zero-lag exponential moving average (ZLEMA) is a variation of the EMA
(@pxref{Exponential Moving Average}) which adds a momentum term aiming to
reduce lag in the average so as to track current prices more closely.  For a
given N-day period the formula is

@tex
$$ ZLEMA = EMA \; of \; (close + (close-close[lag])) $$
@end tex
@ifnottex
@example
ZLEMA = EMA of (close + (close-close[lag]))
@end example
@end ifnottex

doc/chart.texi  view on Meta::CPAN


The calculation still ends up as various weights on each past price.  The
effect of the momentum term is to make recent prices ``over weight'' and thus
tracked closely, and with negative weights on past terms.  There's a sudden
jump in the weights at the momentum lag point.  For example the following
graph is the weights for @math{N=15} (lag point 7).

@myimage{chart-zlema-weights, Zero-lag EMA weights graph}

The EMA lag on a straight line can be calculated easily using the power
formula for the EMA (@pxref{Exponential Moving Average}), applied to an
infinite sequence of prices going downwards by 1 each day and reaching 0 at
today.  On non straight line sequences the lag is not a simple @math{(N-1)/2},
but will vary according to shape, period of cyclical components, etc.


@c ---------------------------------------------------------------------------
@node Channels and Boxes, Indicators, Averages, Top
@chapter Channels and Boxes
@cindex Channels
@cindex Boxes

doc/chart.texi  view on Meta::CPAN

@c ---------------------------------------------------------------------------
@node Accumulation/Distribution, Accumulative Swing Index, Indicators, Indicators
@section Accumulation/Distribution
@cindex Accumulation/distribution
@cindex Index, accumulation/distribution

@cindex Chaikin, Marc
The Accumulation/Distribution index by Marc Chaikin is a cumulative total
volume, with volume each day added or subtracted in proportion to where the
close is between that day's high and low.  For @var{c}, @var{h}, @var{l},
@var{v} and with @ms{AD,prev} as yesterday's Acc/Dist the formula is

@tex
$$ AD = AD_{prev} + v \> \left( 2 \, {{c-l} \over {h-l}} - 1 \right) $$
@end tex
@ifnottex
@example
                       C - L
AD = ADprev + V * (2 * ----- - 1)
                       H - L
@end example

doc/chart.texi  view on Meta::CPAN


@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]

doc/chart.texi  view on Meta::CPAN

tends to become very unresponsive.

@subsection Additional Resources

@itemize
@item
@uref{http://www.linnsoft.com/tour/techind/cog.htm} -- sample graph of Intel
(symbol @samp{INTC}) from 2001/2.
@item
@uref{http://www.working-money.com/Documentation/FEEDbk_docs/Archive/082002/TradersTips/TradersTips.html}
-- formulas in TASC Trader's tips August 2002 (for article from May 2002).
@end itemize


@c ---------------------------------------------------------------------------
@node Chaikin Money Flow, Chaikin Oscillator, Centre of Gravity Oscillator, Indicators
@section Chaikin Money Flow
@cindex Chaikin money flow
@cindex Money flow, Chaikin
@cindex Index, Chaikin money flow

@cindex Chaikin, Marc
The Chaikin money flow index by Marc Chaikin is based on the
Accumulation/Distribution index calculations
(@pxref{Accumulation/Distribution}), but just within a past N-day window.  The
formula is

@tex
$$
Chaikin\,MF = { {total N day \;\; volume *
                \left( 2 {{close - low} \over {high - low}} - 1 \right) }
               \over total N day \;\; volume }
$$
@end tex
@ifnottex
@example

doc/chart.texi  view on Meta::CPAN

     \over SMA[N] \; of \; \left| close - prev\;close \right| } $$
@end tex
@ifnottex
@example
            SMA[N] of   (close - prev close)
CMO = 100 * ---------------------------------
            SMA[N] of  abs(close - prev close)
@end example
@end ifnottex

The formula can also be written in the style of the RSI, with U=close-prev on
an up day, and D=prev-close on a down day.

@tex
$$ CMO = { SMA[N] \; of \; (close - prev\;close)
     \over SMA[N] \; of \; \left| close - prev\;close \right| } $$
@end tex
@ifnottex
@example
                          SMA[N] of U
CMO = -100 + 200 * -------------------------

doc/chart.texi  view on Meta::CPAN

@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

doc/chart.texi  view on Meta::CPAN

@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

doc/chart.texi  view on Meta::CPAN

@c ---------------------------------------------------------------------------
@node On-Balance Volume, Negative Volume Index, Money Flow Index, Indicators
@section On-Balance Volume
@cindex On-balance volume
@cindex OBV
@cindex Volume, on-balance

On-balance volume (OBV) is a running total of daily volume, with volume on an
up day added and volume on a down day subtracted.  An up day is a close higher
than the previous day's close, and vice versa a down day.  So if @ms{p,1} is
today's close and @ms{p,2} is yesterday's, the formula is simply

@tex
$$ OBV = OBV_{prev} + \left\{ \matrix{  v_1 & \mathop{\rm if} \; p_1 > p_2 \cr
                                          0 & \mathop{\rm if} \; p_1 = p_2 \cr
                                       -v_1 & \mathop{\rm if} \; p_1 < p_2 \cr
   } \right. $$
@end tex
@ifnottex
@example
                 /  v1     if p1 > p2

doc/chart.texi  view on Meta::CPAN

@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

doc/chart.texi  view on Meta::CPAN

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

doc/chart.texi  view on Meta::CPAN

@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

doc/chart.texi  view on Meta::CPAN

@end example
@end ifnottex

Wilder recommended a smoothing period of N=14, and that's the default in
Chart.  Note also that the period is interpreted by Wilder's reckoning of EMA
smoothing (see @ref{Wilder EMA period}).

An index value of 70 is considered overbought and 30 oversold; those levels
are shown as dashed lines.  The principle is that after a large proportion of
movement in one direction, a reaction the other way becomes likely.  On the
other hand it's easy to see from the formula that a steady progressive trend
(every day up, or every day down) can push the RSI to an extreme and hold it
there.

The term ``relative strength'' also refers to a comparison between a stock and
the overall market.  This is sometimes called ``relative strength
comparative'' to avoid confusion.  This is unrelated to the relative strength
and relative strength index described in this section.

See also CMO (@pxref{Chande Momentum Oscillator}) which is an RSI with SMA
smoothing, and TSI (@pxref{True Strength Index}) which is an RSI with

doc/chart.texi  view on Meta::CPAN

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

doc/chart.texi  view on Meta::CPAN

@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

doc/chart.texi  view on Meta::CPAN

@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
as small as possible (hence the name ``least squares''), and there's just one
line with that smallest SumSquares.  The calculation is made easier if the X
coordinates are shifted so that @math{Mean(X)=0}.  With that the formulas for
@math{a} and @math{b} are

@tex
$$ a = Mean \; Y = { y_1 + \cdots + y_N \over N } $$
$$ b = { x_1 y_1 + \cdots x_N y_N \over x_1^2 \cdots + x_N^2 } $$
@end tex
@ifnottex
@example
             y1 + ... + yN
a = Mean Y = -------------

doc/chart.texi  view on Meta::CPAN

a data set deviate from their average (mean).  The stddev of a past N days is
used in the calculation of Bollinger bands (@pxref{Bollinger Bands}) and VIDYA
and @ref{Variable Index Dynamic Average}).

The raw stddev values can be shown in Chart as an indicator, to see what goes
into those calculations.  The values have little direct use though, and for
that reason stddev is under ``Low Priority'' in the indicator lists.

@cindex Quadratic mean
@cindex Mean, quadratic
For reference, the formula on prices @ms{p,1} to @ms{p,N} is as follows.  Each
@m{p_i-m,p[i]-m} is the distance from the mean @math{m}, and those distances
are averaged with a quadratic mean.

@tex
$$ \sigma = { \sqrt{ { (p_1-m)^2 + (p_2-m)^2 + \cdots + (p_N-m)^2 } \over N }}
$$
@end tex
@ifnottex
@example
               / (p1-m)^2 + (p2-m)^2 + ... + (pN-m)^2 \

doc/chart.texi  view on Meta::CPAN

$$ m = { { p_1 + p_2 + \cdots + p_N } \over N } $$
@end tex
@ifnottex
@example
    p1 + p2 + ... + pN
m = ------------------
            N
@end example
@end ifnottex

Also, for reference, the formula can be rearranged to the following form,
``sum of the squares minus square of the sums''.  This is what Chart uses,
because a new term can be shifted into the sums without recalculating all N
terms.

@tex
$$ \sigma = { \sqrt{ { { p_1^2 + p_2^2 + \dots + p_N^2 } \over N }
            - { \left( { p_1 + p_2 + \dots + p_N } \over N \right)^2 }}}
$$
@end tex
@ifnottex

doc/chart.texi  view on Meta::CPAN

@cindex SES spreadsheet

@cindex @file{example.ses}
@code{chart-latest} above can be used in SES (@CHARTpxreftop{ses, Simple Emacs
Spreadsheet}) expressions to include prices in a portfolio etc.  See
@file{emacs/example.ses} in the Chart sources for a sample spreadsheet doing
this.

Since @code{chart-latest} doesn't download new data an
@kbd{M-x ses-recalculate-all} just shows existing downloaded quotes
(@pxref{Formulas, @code{ses-recalculate-all}, Cell formulas, ses, SES: Simple
Emacs Spreadsheet}).

@findex @code{chart-ses-refresh}
@kbd{M-x chart-ses-refresh} does a combination @code{ses-recalculate-all} and
download of Chart prices used.  A first recalculate records calls to
@code{chart-latest} for which prices are used in the spreadsheet, they're
downloaded, then a second recalculate applies the new data.  (Further rounds
of download and recalculate are done as necessary if conditionals in
expressions use yet more symbols.)

emacs/chartprog.el  view on Meta::CPAN

;;;###autoload
(defun chart-ses-refresh ()
  "Refresh Chart prices in a SES spreadsheet.
`ses-recalculate-all' is run first to find what `chart-latest'
prices are required.  Then quotes for those symbols are
downloaded and `ses-recalculate-all' run a second time to update
the spreadsheet with the new prices.

If the second `ses-recalculate-all' uses prices for further
symbols, perhaps due to tricky conditionals in spreadsheet
formulas, then another downloaded and `ses-recalculate-all' is
done.  This is repeated until all prices used in the recalculate
have been downloaded."

  (interactive)
  (let (fetched)
    (while (let ((record
                  (let ((chartprog-latest-record-calls (vector nil)))
                    (ses-recalculate-all)
                    (aref chartprog-latest-record-calls 0)))
                 want)

lib/App/Chart/Series/Calculation.pm  view on Meta::CPAN

      return 0;
    }
    return (List::Util::sum (map {$a[$_] * $weights[$_]} 0 .. $#a)
            / $total_weight);
  };
}

#------------------------------------------------------------------------------

# http://mathworld.wolfram.com/LeastSquaresFitting.html
#     Least squares generally, including deriving formula using
#     derivative==0 as follows:
#
#     The sum of squares is
#
#         R^2(a,b) = Sum (y[i] - (a + b*x[i]))^2
#
#     Partial derivative with b is
#
#         d R^2(a,b)
#         ---------- = Sum 2 * (y[i]-b*x[i]) * -x[i]

lib/App/Chart/Series/Derived/CCI.pm  view on Meta::CPAN

use Carp;
use List::Util qw(min max);
use Locale::TextDomain ('App-Chart');

use base 'App::Chart::Series::Indicator';
use App::Chart::Series::Calculation;
use App::Chart::Series::Derived::TypicalPrice;
use App::Chart::Series::Derived::WilliamsR;

# http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:commodity_channel_index_cci
#    Description, formula, sample of Brooktrout BRKT from 1999/2000 (no
#    longer available from Yahoo).
#
# http://www.incrediblecharts.com/indicators/commodity_channel_index.php
#    Description, formula, sample of IBM from 1999.
#

sub longname  { __('CCI - Commodity Channel Index') }
sub shortname { __('CCI') }
sub manual    { __p('manual-node','Commodity Channel Index') }

use constant
  { type       => 'indicator',
    units      => 'CCI',
    hlines     => [ -100,  100 ],

lib/App/Chart/Series/Derived/CMO.pm  view on Meta::CPAN

use Carp;
use List::Util qw(min max);
use Locale::TextDomain ('App-Chart');

use base 'App::Chart::Series::Indicator';
use App::Chart::Series::Calculation;
use App::Chart::Series::Derived::MFI;
use App::Chart::Series::Derived::SMA;


# http://www.equis.com/customer/resources/formulas/formula.aspx?Id=8
#     Metastock formulas.
#
# http://trader.online.pl/MSZ/e-w-Chandes_Momentum_Oscillator.html
#     Formulas and text from equis.com.
#


sub longname   { __('CMO - Chande Momentum Oscillator') }
sub shortname  { __('CMO') }
sub manual     { __p('manual-node','Chande Momentum Oscillator') }

lib/App/Chart/Series/Derived/COG.pm  view on Meta::CPAN



# http://www.mesasoftware.com/technicalpapers.htm
# http://www.mesasoftware.com/Papers/The%20CG%20Oscillator.pdf
#     Paper by John Elhers.
#
# http://www.linnsoft.com/tour/techind/cog.htm
#     Sample Intel (INTC) 2001/2.
#
# http://www.working-money.com/Documentation/FEEDbk_docs/Archive/082002/TradersTips/TradersTips.html
#     Trader's tips August 2002, formulas from May 2002.
#


sub longname   { __('Centre of Gravity') }
sub shortname  { __('COG') }
sub manual     { __p('manual-node','Centre of Gravity Oscillator') }

use constant
  { type       => 'indicator',
    maximum    => -1,

lib/App/Chart/Series/Derived/EMAx2.pm  view on Meta::CPAN

}

# By priming an EMA-2 pro with warmup_count() many values, the next call
# will have an omitted weight of no more than 0.1% of the total.  Omitting
# 0.1% should be negligable, unless past values are ridiculously bigger than
# recent ones.
#
# The implementation here does a binary search for the first k satisfying
# R(k)<=0.001, so it's only moderately fast.  Perhaps there'd be a direct
# closed-form solution to the equation R(k)=0.001 below.  The inverse of
# k*f^k is close to the Lambert W-function.  Is there an easy formula for
# that?
#
sub warmup_count {
  my ($self_or_class, $N) = @_;

  if ($N <= 1) { return 0; }
  my $f = App::Chart::Series::Derived::EMA::N_to_f ($N);
  return bsearch_first_true
    (sub {
       my ($i) = @_;

lib/App/Chart/Series/Derived/EPMA.pm  view on Meta::CPAN

# http://www.traderslog.com/time-series-forecast.htm   (same chart)
#     Sample chart of fisher scientific .. but what symbol, what year?
#
# 
# As "Modified Moving Average":
#
# http://www.traders.com/Documentation/FEEDbk_docs/Archive/012000/Abstracts_new/Sharp/Sharp.html
#     Start of Joe Sharp's TASC article January 2000 (rest for sale).
#
# http://www.traders.com/Documentation/FEEDbk_docs/Archive/012000/TradersTips/TradersTips.html
#     TASC traders' tips January 2000, various formulas.
#     Technifilter coefficients look doubtful.
#
# http://www.traders.com/Documentation/FEEDbk_docs/Archive/062000/Letters/Letters.html
#     TASC letters June 2000, Tim O'Sullivan pointing out MMA is the same
#     as EPMA.
#
# http://www.linnsoft.com/tour/techind/mma.htm
#     Formula, but sample chart is only an intraday.
#
# http://trader.online.pl/MSZ/e-w-Modified_Moving_Average.html
#     Formulas for N=2, N=3, N=4, and N=10.
# http://trader.online.pl/MSZ/e-w-Modified_Moving_Average_II.html
#     Formulas for N=20.
# http://trader.online.pl/ELZ/t-i-Modified_Moving_Averages.html
#     Formula for general N, per traders tips, from www.omegaresearch.com.
#     Sample chart S&P 500 (yahoo symbol ^GSPC) from 2001, looks like the
#     default N=2 shown in the formula.
#
# http://www.tradecision.com/support/tasc_tips/modified_moving_average.htm
# http://www.tradecision.com/downloads/tasc_tips/ModifiedMovingAverage.tnd
#     Formula.
#

#-----------------------------------------------------------------------------

# The equivalence of the linreg a+b*endpos and the "3i" stepping weighted
# moving average is easily shown.  With a=mean, b=slope, p0 today, p1

lib/App/Chart/Series/Derived/GAPO.pm  view on Meta::CPAN


use base 'App::Chart::Series::Indicator';

# http://trader.online.pl/MSZ/e-w-Gopalakrishnan_Range_Index_GAPO.html
#     Formula, sample chart for WIG something.
#
# http://www.tradingsolutions.com/download/tip0105.zip
#     Formula.
#
# http://www.traders.com/Documentation/FEEDbk_docs/Archive/012001/TradersTips/TradersTips.html
#     Traders tips formulas for several packages.  Small sample chart of
#     ^IXIC nasdaq composite for 2000.
#
# http://www.traders.com/Documentation/FEEDbk_docs/Archive/012001/Abstracts_new/Jayanthi/Jayanthi.html
#     First few paras of article.
#
# http://store.traders.com/v19114gopran.html
#     Article for sale, first para only.


sub longname   { __('GAPO') }

lib/App/Chart/Series/Derived/HullMA.pm  view on Meta::CPAN

use Locale::TextDomain ('App-Chart');
use Math::Trig ();

use base 'App::Chart::Series::Indicator';
use App::Chart::Series::Derived::WMA;


# http://www.alanhull.com/
# http://www.alanhull.com.au/
# http://www.justdata.com.au/Journals/AlanHull/hull_ma.htm
#     Alan Hull's explanation and formula, samples of BHP Billiton (symbol
#     BHP.AX) weekly 2001-2004.
#
# Old link: http://www.alanhull.com.au/hma/hma.html
#


sub longname   { __('Hull MA') }
*shortname = \&longname;
sub manual     { __p('manual-node','Hull Moving Average') }

lib/App/Chart/Series/Derived/KAMA.pm  view on Meta::CPAN

use App::Chart::Series::Calculation;
use App::Chart::Series::Derived::KAMAalpha;

use constant DEBUG => 0;


# http://www.traders.com/Documentation/FEEDbk_docs/Archive/0398/TradersTips/Tips9803.html
#    Traders tips March 1998: metastock and easylanguage code
#
# http://www.perrykaufman.com
#    Perry Kaufman's web site (no formulas).
# 
# http://www.tssupport.com/support/base/?action=article&id=1769
#    Short tradestation article, incl EFS code.
#
# Code uses close() to close(-period), so N differences and N+1 total
# points.
#


sub longname  { __('KAMA - Kaufmann Adaptive MA') }

lib/App/Chart/Series/Derived/KVOforce.pm  view on Meta::CPAN

use List::Util qw(min max);
use Locale::TextDomain ('App-Chart');

use base 'App::Chart::Series::Indicator';
use App::Chart::Series::Derived::MFI;

use constant DEBUG => 0;


# http://www.traders.com/Documentation/FEEDbk_docs/Archive/1297/TradersTips/Tips9712.html
#     Traders Tips December 1997 formulas.
#
# http://trader.online.pl/ELZ/t-i-Klinger_Volume_Oscillator.html
#     Repeat of EasyChart section of traders tips above.
#
# http://www.prophet.net/learn/taglossary.jsp?index=K
#     Sample chart of intel (INTC) Nov02-Feb03, KVO and also histogram.
# http://www.prophet.net/analyze/popglossary.jsp?studyid=KVO
#     Same chart of INTC, but just the KVO not the histogram.


lib/App/Chart/Series/Derived/LinRegStderr.pm  view on Meta::CPAN


  return $class->SUPER::new
    (parent     => $parent,
     N          => $N,
     parameters => [ $N ],
     arrays     => { values => [] },
     array_aliases => { });
}
*warmup_count = \&App::Chart::Series::Derived::SMA::warmup_count; # $N-1

# Return the factor for 1/Variance(X) arising in the stderr formula.  With
# X values -1.5,-0.5,0.5, 1.5 this means
#
#                         1
#      --------------------------------------------
#      n * ((-1.5)^2 + (-0.5)^2 + (0.5)^2 + (1.5)^2)
#
# and the denominator here is (n^4 - n^2)/12.  See devel/ema-omitted.pl for
# checking this.  Same func in RSquared.pm too.
#
sub xfactor {

lib/App/Chart/Series/Derived/MFI.pm  view on Meta::CPAN

use base 'App::Chart::Series::Indicator';
use App::Chart::Series::Derived::RSI;
use App::Chart::Series::Derived::TypicalPrice;


# http://www.linnsoft.com/tour/techind/mfi.htm
#     Formula, and sample Apple (AAPL) from 1999/2000 as 9-day MFI smoothed
#     by 7-day SMA.
#

# The MFI formula is sometimes written
#
#                      /       100       \
#                     |  ---------------  |
#         MFI = 100 - |      positive MF  |
#                     |  1 + -----------  |
#                      \     negative MF /
#
#
# but it's much easier to rearrange that to what's shown in the manual,
#

lib/App/Chart/Series/Derived/NATR.pm  view on Meta::CPAN

use warnings;
use Carp;
use Locale::TextDomain 1.17; # for __p()
use Locale::TextDomain ('App-Chart');

use base 'App::Chart::Series::Indicator';
use App::Chart::Series::Derived::ATR;
use App::Chart::Series::Derived::WilliamsR;

# http://www.traders.com/Documentation/FEEDbk_docs/Archive/052006/TradersTips/TradersTips.html
#     TASC Trader's Tips May 2006, various formulas.
#
# http://www.theessentialsoftrading.com/Blog/index.php/category/technical-analysis/
#     Blog by John Forman, sample of S&P500 back to 1980.
#
# http://www.trade2win.com/knowledge/articles/general_articles/average-true-range-indicator/
#     Article by John Forman (2 pages), sample of monthly S&P 500 from 1998
#     to 2007 comparing ATR to NATR (seems to be 14-period smoothing).
# http://www.trade2win.com/knowledge/articles/general_articles/average-true-range-indicator/page2
#     Continuing that article, sample of monthly S&P 500 from 1986 to 2006
#     comparing ATR to NATR (again seems to be 14-period smoothing).

lib/App/Chart/Series/Derived/PGO.pm  view on Meta::CPAN



# http://www.purebytes.com/archives/omega/1999/msg12885.html
#
# http://www.mjohnson.com/trecipes/pgoy2k.zip   [gone]
#
# http://trader.online.pl/MSZ/e-w-Pretty_Good_Oscillator.html
#    Sample CSCO
#
# http://xeatrade.com/trading/2/P/1139.html
#    Metastock formula copied from http://www.traderclub.com, showing EMA[89]
#
#
# http://www.elitetrader.com/vb/printthread.php?threadid=18598
#    Bit of discussion from Nov 2003.
#

sub longname   { __('PGO - Pretty Good Oscillator') }
sub shortname  { __('PGO') }
sub manual     { __p('manual-node','Pretty Good Oscillator') }

lib/App/Chart/Series/Derived/REMA.pm  view on Meta::CPAN

use Locale::TextDomain ('App-Chart');
use Math::Trig ();

use base 'App::Chart::Series::Indicator';
use App::Chart::Series::Derived::EMA;

# http://www.traders.com/Documentation/FEEDbk_docs/Archive/072003/Abstracts_new/Satchwell/satchwell.html
#     Start of TASC August 2003 article by Chris Satchwell.
#
# http://www.traders.com/Documentation/FEEDbk_docs/Archive/072003/TradersTips/TradersTips.html
#     TASC Traders' Tips August 2003, regularization formulas.
#
# http://www.traders.com/Documentation/FEEDbk_docs/Archive/092003/Letters/Letters.html
#     TASC letters September 2003, Chris Satchwell clarifying derivation of
#     formula.
#
# http://www.equis.com/Customer/Resources/TASC/Article.aspx?Id=50
#     Metastock code for regularized EMA and regularized momentum.
#
# http://trader.online.pl/ELZ/t-i-Regularization.html
#     Easylanguage code, copy of trader's tips.
#

sub longname   { __('REMA - Regularized EMA') }
sub shortname  { __('REMA') }

lib/App/Chart/Series/Derived/REMA.pm  view on Meta::CPAN

# no more than 0.1% of the total.  Omitting 0.1% should be negligable,
# unless past values are ridiculously bigger than recent ones.
#
# FIXME: probably shorter than the full EMA when lambda > 0
#
sub warmup_count {
  my ($class_or_self, $N, $lambda) = @_;
  return 2 * App::Chart::Series::Derived::EMA->warmup_count ($N / $lambda);
}

# The formula
#
#            Rprev * (2L+1) + alpha*(close - Rprev) - L*Rprevprev
#     REMA = ----------------------------------------------------
#                                L+1
#
# is turned into the followering, in the style of the AmiBroker code in
# Trader's Tips above,
#
#            a*close + b*Rprev + c*Rprevprev
#     REMA = -------------------------------

lib/App/Chart/Series/Derived/RSquared.pm  view on Meta::CPAN

use App::Chart::Series::Derived::SMA;

use constant DEBUG => 0;


# http://www.traderslog.com/r-squared.htm
#     Sample Coors (NYSE symbol "TAP") from Feb 2002 (the year isn't shown,
#     but is 2002).
#
# http://mathworld.wolfram.com/CorrelationCoefficient.html
#     Explanation of general case, incl formulas.
#


sub longname  { __('R-Squared Index') }
sub shortname { __('R-Squared') }
sub manual    { __p('manual-node','R-Squared Index') }

use constant
  { type       => 'indicator',
    units      => 'zero_to_one',

lib/App/Chart/Series/Derived/RSquared.pm  view on Meta::CPAN

sub triangular {
  my ($n) = @_;
  return $n * ($n+1) / 2;
}

sub proc {
  my ($class, $N) = @_;

  # This is the correlation coefficient of the last COUNT many X values,
  # against a set of Y values 1, 2, 3, ..., COUNT.  Or fewer than COUNT
  # until that many values have been seen.  The formula in the manual is
  #
  #                (Covariance X,Y)^2
  #     r^2 = ---------------------------
  #           (Variance X) * (Variance Y)
  #
  # which is
  #
  #                       (Sum X*Y)/N - (Sum X)/N * (Sum Y)/N
  #     r^2 = -------------------------------------------------------------
  #           ((Sum X^2)/N - (Sum X)^2/N^2) * ((Sum Y^2)/N - (Sum Y)^2/N^2)

lib/App/Chart/Series/Derived/RVI.pm  view on Meta::CPAN


# http://www.fmlabs.com/reference/RVI.htm
#     Formula, some description.
#
# http://trader.online.pl/MSZ/e-w-Relative_Volatility_Index_RVI.html
#     Reproducing equis.com original 1993 version, adding sample of Kredyt
#     Bank (which is not in Yahoo, or only as .PK pink sheets).
# http://trader.online.pl/MSZ/e-w-Inertia.html
#     1995 revision.
#
# http://www.equis.com/customer/resources/formulas/formula.aspx?Id=52
#     Original 1993.
#
# http://store.traders.com/-v11-c06-therela-pdf.html
#     TASC 1993.
#
# http://store.traders.com/-v13-c09-refinin-pdf.html
#     TASC 1995, high/low combination, and introducing Inertia.
#
# http://store.traders.com/v1340tradtip.html
#     TASC traders tips for sale.

lib/App/Chart/Series/Derived/RWI.pm  view on Meta::CPAN

#     one-day move) over square root.
# http://store.traders.com/-v11-c11-sideran-pdf.html
#     Similar.
#     "Are There Persistent Cycles", E. Michael Poulos, September 1992
#     TASC.
#
# http://www.prophet.net/analyze/popglossary.jsp?studyid=RWI
#     Sample of McDonalds, year not shown but looks like May 2001.
#
# http://www.paritech.com/paritech-site/education/technical/indicators/momentum/random.asp
#     Description, no formulas, sample of DJS.AX, year not shown but is
#     1999 (RWI period not shown either).
#
# http://trader.online.pl/MSZ/e-w-Random_Walk_Index.html
#     Formula.
#
# http://trader.online.pl/MSZ/e-w-Random_Walk_Index_II.html
#     Long and short term high and low forms.  Chart of Telecom Polska
#     (TPSA.WA, London international order book TPSD.IL).
#
# http://www.linnsoft.com/tour/techind/ranWalk.htm
#     Formula.
#
# http://www.equis.com/customer/resources/formulas/formula.aspx?Id=48
#     Metastock formula, but only the RWI High part
#
# http://xeatrade.com/trading/2/R/1160.html
#     Metastock formula.
#
# http://www.tradecision.com/support/indicators/random_walk_index.htm
#     Tradedecsion formula for 9-day, cumulative sum of 1-day ATRs.
#
# http://technical.traders.com/tradersonline/display.asp?art=606
#     Dennis Peterson on a random walk trading system.  Sample Nasdaq
#     composite (QQQ, yahoo now ^IXIC) from 1999/2000.
#
# http://www.sirtrade.com/serv03.htm
#     Sample code of programming service by Pierre Orphelin, having
#     struggled a bit with the correct definition.  (Rejected incorrect
#     code using the highest high in the past N days, maybe.)
#

lib/App/Chart/Series/Derived/TDREI.pm  view on Meta::CPAN

#
# http://secure.aspenres.com/Documents/help/userguide/help/dmrkhelp/demarkRange_Expansion_Index.html
#     Description, sample of CME S&P 500 futures SPU05.CME.
#
# http://www.traders.com/documentation/feedbk_docs/archive/0897/Abstracts_new/DeMark/DEMARK9708.html
# http://store.traders.com/-v15-c08-thetdra-pdf.html
#     Intro to Tom DeMark "The TD Range Expansion Index (TD REI)" TASC 15:8
#     August 1997 (rest for sale), revising original from his book "The New
#     Science of Technical Analysis".
#
# http://www.meta-formula.com/Metastock-Formulas-T.html
#     Formula.
#
# http://www.amibroker.com/library/formula.php?id=15
#     Formula, showing only numerator suppressed by condition.
#
# http://www.aiqsystems.com/PriceandVolumeBasedStrategies1.htm#down17
#     Code.
# http://www.aiqsystems.com/TDREI.gif
#     Sample of Cabot Corp (NYSE symbol CBT) from Jan to Jun 2002.  Period
#     not shown, looks like 5 days.
#

sub longname   { __('TD REI - Range Expansion Index') }

lib/App/Chart/Series/Derived/TSI.pm  view on Meta::CPAN

#
# http://store.traders.com/-v10-c05-trading-pdf.html
#     "Trading With the True Strength Index", William Blau, TASC V.10:5
#     May 1992 by William Blau.  Intro, rest for sale.
#
# http://store.traders.com/-v11-c01-sidetru-pdf.html
#     Sidebar included of "Stochastic Momentum" article January 1993.
#     Formula not shown, but 1-day momentum described.
#
# http://www.traders.com/Documentation/FEEDbk_docs/Archive/112005/Letters/Letters.html
#     TASC letters Nov 2005, Perry Kaufman giving formula.
#
# http://www.linnsoft.com/tour/techind/tsi.htm
#     Formula, parameters 9 and 3, sample intraday AOL.
#
# http://www.meta-formula.com/Metastock-Formulas-T.html
#     Formula.
#
# http://trader.online.pl/MSZ/e-w-True_Strength_Index.html
#     Formula with ROC percentage and programmable period.
# http://trader.online.pl/MSZ/e-w-True_Strength_Index_II.html
#     Formula, plain mom, periods 25 and 13.
# http://trader.online.pl/MSZ/e-w-True_Strength_Index_III.html
#     Formula, plain momentum, periods 15 and 5.
# http://trader.online.pl/MSZ/e-w-True_Strength_Index_IV.html
#     Formula, plain momentum, periods 25 and 13.

lib/App/Chart/Series/Derived/VIDYA.pm  view on Meta::CPAN

use App::Chart::Series::Derived::KAMA;
use App::Chart::Series::Derived::VIDYAalpha;


# http://trader.online.pl/ELZ/t-i-VIDYA.html
#     Formulas and S&P500 sample chart.
#
# http://www.fmlabs.com/reference/VIDYA.htm
#
# http://www.working-money.com/documentation/FEEDbk_docs/Archive/0298/TradersTips/Tips9802.html
#     TASC trader's tips February 1998, formulas.
#


sub longname   { __('VIDYA - Variable Index Dynamic') }
sub shortname  { __('VIDYA') }
sub manual     { __p('manual-node','Variable Index Dynamic Average') }

use constant
  { type       => 'average',
    parameter_info => App::Chart::Series::Derived::VIDYAalpha::parameter_info(),

lib/App/Chart/Series/Derived/ZLEMA.pm  view on Meta::CPAN

     parameters => [ $N ],
     N          => $N,
     lag        => int (($N - 1) / 2),  # (N-1)/2
     arrays     => { values => [] },
     array_aliases => { });
}

# Lag calculation:
#
# Taking a decreasing sequence with today price 0, yesterday price 1, the
# day before 2, etc, then the EMA today using the power formula is
#
#     EMA = (1-f) * (0 + 1*f + 2*f^2 + 3*f^3 + 4*f^4 + ...)
#
# Multiplying through gives
#
#     EMA = 0 + 1*f + 2*f^2 + 3*f^3 + 4*f^4 + ...
#             - 0*f - 1*f^2 - 2*f^2 - 3*f^4 - ...
#
#         = f + f^2 + f^3 + f^4 + ...
#

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<a class="index-entry-id" id="index-Moving-average_002c-exponential"></a>

<p>An N-day exponential moving average (EMA) is a weighted average of today&rsquo;s
close and the preceding EMA value.  The weight for today&rsquo;s close is a
smoothing factor alpha, where <em class="math">alpha=2/(N+1)</em>.
</p>
<div class="example">
<pre class="example-preformatted">EMA[today] = alpha * close + (1-alpha) * EMA[yesterday]
</pre></div>

<p>The formula can also be written as follows, showing how the average moves
towards today&rsquo;s close by an alpha fraction of the distance from the old EMA
to the new close.
</p>
<div class="example">
<pre class="example-preformatted">EMA[today] = EMA[yesterday] + alpha * (close + EMA[yesterday])
</pre></div>

<p>Expanding out gives a power series with successively decreasing weight for
each day&rsquo;s price.  Writing <em class="math">f=1-alpha</em> and with p1 today&rsquo;s
closing price, p2 yesterday&rsquo;s, etc, then

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<p>When working with N-day periods, it should be noted that J. Welles Wilder
uses a different reckoning of the decrease factor for EMAs.  For example for a
14-day EMA he writes
</p>
<div class="example">
<pre class="example-preformatted">              1           13
EMA[today] = -- * close + -- * EMA[yesterday]
             14           14
</pre></div>

<p>This is the same as the formula above, just a different <em class="math">f</em> factor.  When
Wilder gives &ldquo;W&rdquo; days, the equivalent &ldquo;N&rdquo; above is <em class="math">2*W-1</em>, so say
14 becomes 27.  This is also sometimes called a &ldquo;modified moving average&rdquo;.
</p>
<p>In the indicators designed by Wilder, Chart uses his reckoning, so that for
instance a 14-day RSI is entered at 14.  This applies to ATR, DMI (and ADX)
and RSI (see <a class="pxref" href="#Average-True-Range">Average True Range</a>, <a class="ref" href="#Directional-Movement-Index">Directional Movement Index</a>, and
<a class="ref" href="#Relative-Strength-Index">Relative Strength Index</a>).
</p>

<hr>

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<a class="index-entry-id" id="index-Weighted-moving-average"></a>
<a class="index-entry-id" id="index-WMA"></a>
<a class="index-entry-id" id="index-Average_002c-weighted"></a>
<a class="index-entry-id" id="index-Moving-average_002c-weighted"></a>

<p>An N-day weighted moving average is an average of today&rsquo;s close and preceding
closes, with weighting factor N for today, <em class="math">N-1</em> for yesterday,
<em class="math">N-2</em> for the day before, etc.  The influence of past data thereby
decreases with its age, down to nothing beyond N days.
</p>
<p>The formula is as follows, with p1 for today&rsquo;s closing price, p2
yesterday&rsquo;s, etc.
</p>
<div class="example">
<pre class="example-preformatted">      N * p1 + (N-1) * p2 + (N-2) * p3 + ... + 2 * p[N-1] + pN
WMA = --------------------------------------------------------
        N    +    N-1     +     N-2    + ... +    2       + 1
</pre></div>

<p>Like the EMA (see <a class="pxref" href="#Exponential-Moving-Average">Exponential Moving Average</a>), the WMA gives a higher
weighting to recent prices than past prices, so it tracks those recent prices

lib/App/Chart/doc/chart.html  view on Meta::CPAN


<p>The endpoint moving average (EPMA) establishes an average price by fitting a
least squares straight line (see <a class="pxref" href="#Linear-Regression">Linear Regression</a>) through the past N
days closing prices and taking the endpoint of the line (ie. the line as at
the last day) as the average.
</p>
<p>This calculation goes by a number of other names, including least squares
moving average (LSQMA), moving linear regression, and time series forecast
(TSF).  Joe Sharp&rsquo;s &ldquo;modified moving average&rdquo; is the same thing too.
</p>
<p>The formula ends up being a straightforward weighted average of past N prices,
with weights going from <em class="math">2*N-1</em> down to <em class="math">-N+2</em>.  This is easily
derived from the least squares formulas, but just looking at the weightings
the connection to least squares is not at all obvious.  If p1 is today&rsquo;s
close, p2 yesterdays, etc, then
</p>
<div class="example">
<pre class="example-preformatted">       (2*N-1)*p[1] + (2*N-4)*p[2] + ... + (-N+2)*p[N]
EPMA = -----------------------------------------------
        2*N-1       +  2*N-4       + ... +  -N+2
</pre></div>

<p>The weights decrease by 3 for each older day, and go negative for the oldest

lib/App/Chart/doc/chart.html  view on Meta::CPAN

lower indicator window, to see where they&rsquo;re big or small, under &ldquo;Low
Priority&rdquo; near the end of the indicators lists.
</p>
<ul class="mini-toc">
<li><a href="#Additional-Resources" accesskey="1">Additional Resources</a></li>
</ul>
<div class="subsection-level-extent" id="Additional-Resources">
<h4 class="subsection"><span>8.6.1 Additional Resources<a class="copiable-link" href="#Additional-Resources"> &para;</a></span></h4>
<ul class="itemize mark-bullet">
<li><a class="uref" href="http://www.traders.com/Documentation/FEEDbk_docs/Archive/102005/TradersTips/TradersTips.html">http://www.traders.com/Documentation/FEEDbk_docs/Archive/102005/TradersTips/TradersTips.html</a>
&ndash; TASC Oct 2005 Traders&rsquo; Tips various formulas [possibly gone].
</li></ul>


<hr>
</div>
</div>
<div class="section-level-extent" id="Guppy-Multiple-Moving-Average">
<div class="nav-panel">
<p>
Next: <a href="#Hull-Moving-Average" accesskey="n" rel="next">Hull Moving Average</a>, Previous: <a href="#Fractal-Adaptive-Moving-Average" accesskey="p" rel="prev">Fractal Adaptive Moving Average</a>, Up: <a href="#Averages" accesskey="u" rel="up">A...

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<h3 class="section" id="Regularized-Exponential-Moving-Average-1"><span>8.14 Regularized Exponential Moving Average<a class="copiable-link" href="#Regularized-Exponential-Moving-Average-1"> &para;</a></span></h3>
<a class="index-entry-id" id="index-Regularized-exponential-moving-average"></a>
<a class="index-entry-id" id="index-REMA"></a>
<a class="index-entry-id" id="index-Average_002c-regularized-exponential"></a>
<a class="index-entry-id" id="index-Moving-average_002c-regularized-exponential"></a>
<a class="index-entry-id" id="index-Exponential-moving-average_002c-regularized"></a>

<a class="index-entry-id" id="index-Satchwell_002c-Chris"></a>
<p>The regularized exponential moving average (REMA) by Chris Satchwell is a
variation on the EMA (see <a class="pxref" href="#Exponential-Moving-Average">Exponential Moving Average</a>) designed to be
smoother but not introduce too much extra lag.  The formula can be given in a
number of forms, such as
</p>
<div class="example">
<pre class="example-preformatted">       Rp + alpha*(close - Rp) + lambda*(Rp + (Rp-Rpp))
REMA = ---------------------------------------------
                 1             +      lambda
</pre></div>
<p>alpha = N-day smoothing per EMA <br>
Rp = yesterday&rsquo;s REMA <br>
Rpp = day before yesterday&rsquo;s REMA <br>

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<p>This is like a Rate of Change (see <a class="pxref" href="#Momentum-and-Rate-of-Change">Momentum</a>), 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).
</p>
</div>
<div class="subsection-level-extent" id="Additional-Resources-3">
<h4 class="subsection"><span>8.14.2 Additional Resources<a class="copiable-link" href="#Additional-Resources-3"> &para;</a></span></h4>
<ul class="itemize mark-bullet">
<li><a class="uref" href="http://www.traders.com/Documentation/FEEDbk_docs/Archive/072003/TradersTips/TradersTips.html">http://www.traders.com/Documentation/FEEDbk_docs/Archive/072003/TradersTips/TradersTips.html</a>
&ndash; TASC Traders&rsquo; Tips, August 2003, REMA and REMA momentum formulas.
</li></ul>


<hr>
</div>
</div>
<div class="section-level-extent" id="Sine-Weighted-Moving-Average">
<div class="nav-panel">
<p>
Next: <a href="#T3-Moving-Average" accesskey="n" rel="next">T3 Moving Average</a>, Previous: <a href="#Regularized-Exponential-Moving-Average" accesskey="p" rel="prev">Regularized Exponential Moving Average</a>, Up: <a href="#Averages" accesskey="u" ...

lib/App/Chart/doc/chart.html  view on Meta::CPAN

</div>
<h3 class="section" id="T3-Moving-Average-1"><span>8.16 T3 Moving Average<a class="copiable-link" href="#T3-Moving-Average-1"> &para;</a></span></h3>
<a class="index-entry-id" id="index-T3-moving-average"></a>

<p>The T3 moving average by Tim Tillson is a triple smoothed combination of the
DEMA (see <a class="pxref" href="#Double-and-Triple-Exponential-Moving-Average">Double and Triple Exponential Moving Average</a>) and a plain EMA
(see <a class="pxref" href="#Exponential-Moving-Average">Exponential Moving Average</a>).
</p>
<p>A given &ldquo;volume factor&rdquo; 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
&ldquo;generalized DEMA&rdquo; is
</p>
<div class="example">
<pre class="example-preformatted">GD(N,v) = (1-v)*EMA[N] + v*DEMA[N]
</pre></div>

<p>or equivalently as follows, emphasising how a portion of the momentum term
present in the DEMA is used,
</p>
<div class="example">

lib/App/Chart/doc/chart.html  view on Meta::CPAN

</div>
<h3 class="section" id="Zero_002dLag-Exponential-Moving-Average-1"><span>8.20 Zero-Lag Exponential Moving Average<a class="copiable-link" href="#Zero_002dLag-Exponential-Moving-Average-1"> &para;</a></span></h3>
<a class="index-entry-id" id="index-zero_002dlag-exponential-moving-average"></a>
<a class="index-entry-id" id="index-Average_002c-zero_002dlag-exponential"></a>
<a class="index-entry-id" id="index-Moving-average_002c-zero_002dlag-exponential"></a>
<a class="index-entry-id" id="index-ZLEMA"></a>

<p>The zero-lag exponential moving average (ZLEMA) is a variation of the EMA
(see <a class="pxref" href="#Exponential-Moving-Average">Exponential Moving Average</a>) which adds a momentum term aiming to
reduce lag in the average so as to track current prices more closely.  For a
given N-day period the formula is
</p>
<div class="example">
<pre class="example-preformatted">ZLEMA = EMA of (close + (close-close[lag]))
</pre></div>

<p>Where the &ldquo;lag&rdquo; period is <em class="math">(N-1)/2</em>.  A plain EMA applied to straight
line points ends up always being the close at <em class="math">(N-1)/2</em> days ago.  So the
idea of adding in this difference &ldquo;close - close[lag]&rdquo; is to compensate for
that lag, to make the ZLEMA track a straight line exactly.  Of course real
data is rarely a straight line, but the principle is to push the ZLEMA towards

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<p>The calculation still ends up as various weights on each past price.  The
effect of the momentum term is to make recent prices &ldquo;over weight&rdquo; and thus
tracked closely, and with negative weights on past terms.  There&rsquo;s a sudden
jump in the weights at the momentum lag point.  For example the following
graph is the weights for <em class="math">N=15</em> (lag point 7).
</p>
<br>
<div class="center"><img class="image" src="chart-zlema-weights.png" alt="Zero-lag EMA weights graph">
</div>
<p>The EMA lag on a straight line can be calculated easily using the power
formula for the EMA (see <a class="pxref" href="#Exponential-Moving-Average">Exponential Moving Average</a>), applied to an
infinite sequence of prices going downwards by 1 each day and reaching 0 at
today.  On non straight line sequences the lag is not a simple <em class="math">(N-1)/2</em>,
but will vary according to shape, period of cyclical components, etc.
</p>

<hr>
</div>
</div>
<div class="chapter-level-extent" id="Channels-and-Boxes">
<div class="nav-panel">

lib/App/Chart/doc/chart.html  view on Meta::CPAN

Next: <a href="#Accumulative-Swing-Index" accesskey="n" rel="next">Accumulative Swing Index</a>, Previous: <a href="#Indicators" accesskey="p" rel="prev">Indicators</a>, Up: <a href="#Indicators" accesskey="u" rel="up">Indicators</a> &nbsp; [<a href=...
</div>
<h3 class="section" id="Accumulation_002fDistribution-1"><span>10.1 Accumulation/Distribution<a class="copiable-link" href="#Accumulation_002fDistribution-1"> &para;</a></span></h3>
<a class="index-entry-id" id="index-Accumulation_002fdistribution"></a>
<a class="index-entry-id" id="index-Index_002c-accumulation_002fdistribution"></a>

<a class="index-entry-id" id="index-Chaikin_002c-Marc"></a>
<p>The Accumulation/Distribution index by Marc Chaikin is a cumulative total
volume, with volume each day added or subtracted in proportion to where the
close is between that day&rsquo;s high and low.  For <var class="var">c</var>, <var class="var">h</var>, <var class="var">l</var>,
<var class="var">v</var> and with ADprev as yesterday&rsquo;s Acc/Dist the formula is
</p>
<div class="example">
<pre class="example-preformatted">                       C - L
AD = ADprev + V * (2 * ----- - 1)
                       H - L
</pre></div>

<p>When the close is at the high the factor is <em class="math">+1</em> and the full volume is
added in, when the close is at the low the factor is <em class="math">-1</em> and the full
volume is subtracted.  In between is in proportion, so for instance a close at

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<p><a class="uref" href="http://www.mesasoftware.com/technicalpapers.htm">http://www.mesasoftware.com/technicalpapers.htm</a> <br>
<a class="uref" href="http://www.mesasoftware.com/Papers/The%20CG%20Oscillator.pdf">http://www.mesasoftware.com/Papers/The%20CG%20Oscillator.pdf</a>
</p>
<a class="index-entry-id" id="index-Ehlers_002c-John-3"></a>
<p>The Centre of Gravity (CG) oscillator by John Ehlers is a comparison of recent
prices against older prices within a given past N days.
</p>
<p>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.
If p1 is today&rsquo;s price, p2 yesterday&rsquo;s, etc, then the formula is
</p>
<div class="example">
<pre class="example-preformatted">       1*p[1] + 2*p[2] + ... + N*p[N]
CG = - ------------------------------
        p[1] +   p[2] + ... +   p[N]
</pre></div>

<p>The &ldquo;<em class="math">-</em>&rdquo; sign puts the CG on a scale of <em class="math">-N</em> at the oldest end,
up to <em class="math">-1</em> at the newest prices end.  But those extremes are not reached,
instead CG hovers around the midpoint <em class="math">-(N-1)/2</em>.  The scale is not

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<ul class="mini-toc">
<li><a href="#Additional-Resources-5" accesskey="1">Additional Resources</a></li>
</ul>
<div class="subsection-level-extent" id="Additional-Resources-5">
<h4 class="subsection"><span>10.5.1 Additional Resources<a class="copiable-link" href="#Additional-Resources-5"> &para;</a></span></h4>

<ul class="itemize mark-bullet">
<li><a class="uref" href="http://www.linnsoft.com/tour/techind/cog.htm">http://www.linnsoft.com/tour/techind/cog.htm</a> &ndash; sample graph of Intel
(symbol &lsquo;<samp class="samp">INTC</samp>&rsquo;) from 2001/2.
</li><li><a class="uref" href="http://www.working-money.com/Documentation/FEEDbk_docs/Archive/082002/TradersTips/TradersTips.html">http://www.working-money.com/Documentation/FEEDbk_docs/Archive/082002/TradersTips/TradersTips.html</a>
&ndash; formulas in TASC Trader&rsquo;s tips August 2002 (for article from May 2002).
</li></ul>


<hr>
</div>
</div>
<div class="section-level-extent" id="Chaikin-Money-Flow">
<div class="nav-panel">
<p>
Next: <a href="#Chaikin-Oscillator" accesskey="n" rel="next">Chaikin Oscillator</a>, Previous: <a href="#Centre-of-Gravity-Oscillator" accesskey="p" rel="prev">Centre of Gravity Oscillator</a>, Up: <a href="#Indicators" accesskey="u" rel="up">Indicat...
</div>
<h3 class="section" id="Chaikin-Money-Flow-1"><span>10.6 Chaikin Money Flow<a class="copiable-link" href="#Chaikin-Money-Flow-1"> &para;</a></span></h3>
<a class="index-entry-id" id="index-Chaikin-money-flow"></a>
<a class="index-entry-id" id="index-Money-flow_002c-Chaikin"></a>
<a class="index-entry-id" id="index-Index_002c-Chaikin-money-flow"></a>

<a class="index-entry-id" id="index-Chaikin_002c-Marc-1"></a>
<p>The Chaikin money flow index by Marc Chaikin is based on the
Accumulation/Distribution index calculations
(see <a class="pxref" href="#Accumulation_002fDistribution">Accumulation/Distribution</a>), but just within a past N-day window.  The
formula is
</p>
<div class="example">
<pre class="example-preformatted">                                     /      close - low     \
              total N-day  volume * |  2 *  ----------- - 1  |
                                     \      high - low      /
Chaikin MF = ------------------------------------------------
                         total N-day  volume
</pre></div>

<p>The Acc/Dist style volume values in the numerator range between <em class="math">+volume</em>

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<a class="index-entry-id" id="index-Chande_002c-Tushar-2"></a>
<p>The Chande Momentum Oscillator (CMO) by Tushar Chande is a variation on the
RSI (see <a class="pxref" href="#Relative-Strength-Index">Relative Strength Index</a>) using an SMA (see <a class="pxref" href="#Simple-Moving-Average">Simple Moving Average</a>) and on a scale between <em class="math">-100</em> and <em class="math">...
</p>
<div class="example">
<pre class="example-preformatted">            SMA[N] of   (close - prev close)
CMO = 100 * ---------------------------------
            SMA[N] of  abs(close - prev close)
</pre></div>

<p>The formula can also be written in the style of the RSI, with U=close-prev on
an up day, and D=prev-close on a down day.
</p>
<div class="example">
<pre class="example-preformatted">                          SMA[N] of U
CMO = -100 + 200 * -------------------------
                   SMA[N] of U + SMA[N] of D
</pre></div>

<p>See also TSI (see <a class="pxref" href="#True-Strength-Index">True Strength Index</a>), another different moving average
for an RSI.

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<a class="index-entry-id" id="index-Force-index"></a>
<a class="index-entry-id" id="index-Index_002c-force"></a>
<a class="index-entry-id" id="index-EFI"></a>
<a class="index-entry-id" id="index-_0025F"></a>

<a class="index-entry-id" id="index-Elder_002c-Alexander-1"></a>
<p>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 <em class="math">change*volume</em> values are
smoothed slightly with a 2-day EMA (see <a class="pxref" href="#Exponential-Moving-Average">Exponential Moving Average</a>), so
the formula is simply
</p>
<div class="example">
<pre class="example-preformatted">Force Index = EMA[2] of (volume * (close - prev close))
</pre></div>

<p>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.
</p>

lib/App/Chart/doc/chart.html  view on Meta::CPAN

</div>
<h3 class="section" id="Forecast-Oscillator-1"><span>10.17 Forecast Oscillator<a class="copiable-link" href="#Forecast-Oscillator-1"> &para;</a></span></h3>
<a class="index-entry-id" id="index-Forecast-oscillator"></a>
<a class="index-entry-id" id="index-Oscillator_002c-forecast"></a>
<a class="index-entry-id" id="index-FOSC"></a>
<a class="index-entry-id" id="index-_0025F-1"></a>

<a class="index-entry-id" id="index-Chande_002c-Tushar-3"></a>
<p>The %F forecast oscillator by Tushar Chande shows deviation between today&rsquo;s
closing price and an N-day linear regression forecast (see <a class="pxref" href="#Linear-Regression">Linear Regression</a>) of that close.  The deviation is expressed as a percentage of the
close, so the formula is
</p>
<div class="example">
<pre class="example-preformatted">     close - forecast
%F = ---------------- * 100
          close

forecast = linear regression of previous N days, at today
</pre></div>

<p>The N days prices for the linear regression start from yesterday&rsquo;s close, and

lib/App/Chart/doc/chart.html  view on Meta::CPAN

Next: <a href="#Negative-Volume-Index" accesskey="n" rel="next">Negative Volume Index</a>, Previous: <a href="#Money-Flow-Index" accesskey="p" rel="prev">Money Flow Index</a>, Up: <a href="#Indicators" accesskey="u" rel="up">Indicators</a> &nbsp; [<a...
</div>
<h3 class="section" id="On_002dBalance-Volume-1"><span>10.26 On-Balance Volume<a class="copiable-link" href="#On_002dBalance-Volume-1"> &para;</a></span></h3>
<a class="index-entry-id" id="index-On_002dbalance-volume"></a>
<a class="index-entry-id" id="index-OBV"></a>
<a class="index-entry-id" id="index-Volume_002c-on_002dbalance"></a>

<p>On-balance volume (OBV) is a running total of daily volume, with volume on an
up day added and volume on a down day subtracted.  An up day is a close higher
than the previous day&rsquo;s close, and vice versa a down day.  So if p1 is
today&rsquo;s close and p2 is yesterday&rsquo;s, the formula is simply
</p>
<div class="example">
<pre class="example-preformatted">                 /  v1     if p1 &gt; p2
                |
OBV = OBVprev + |   0      if p1 = p2
                |
                 \  - v1   if p1 &gt; p2
</pre></div>

<p>The starting point (ie. the zero point) for the running total is arbitrary.

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<a class="index-entry-id" id="index-Fractal_002c-polarized-efficiency-indicator"></a>

<p>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.
</p>
<p>The net distance travelled over the past N days is expressed as a percentage
of the total of each day&rsquo;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 p1 (today) to pN is
</p>
<div class="example">
<pre class="example-preformatted">                   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&gt;0, or -1 if X&lt;0

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

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<p>Johnson&rsquo;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).
</p>
<ul class="mini-toc">
<li><a href="#Additional-Resources-9" accesskey="1">Additional Resources</a></li>
</ul>
<div class="subsection-level-extent" id="Additional-Resources-9">
<h4 class="subsection"><span>10.29.1 Additional Resources<a class="copiable-link" href="#Additional-Resources-9"> &para;</a></span></h4>
<ul class="itemize mark-bullet">
<li><a class="uref" href="http://trader.online.pl/MSZ/e-w-Pretty_Good_Oscillator.html">http://trader.online.pl/MSZ/e-w-Pretty_Good_Oscillator.html</a> &ndash; formula,
and sample chart of Cisco (&lsquo;<samp class="samp">CSCO</samp>&rsquo;) from 2003.
</li></ul>


<hr>
</div>
</div>
<div class="section-level-extent" id="Price-and-Volume-Trend">
<div class="nav-panel">
<p>

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<a class="index-entry-id" id="index-Kroll_002c-Stanley-1"></a>
<a class="index-entry-id" id="index-Correlation-coefficient"></a>
<a class="index-entry-id" id="index-Coefficient_002c-correlation"></a>
<a class="index-entry-id" id="index-Coefficient-of-determination"></a>
<p>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 <em class="dfn">coefficient of determination</em>
of the prices versus a straight line.  This coefficient is written <em class="math">r^2</em>,
hence the name of the indicator.
</p>
<p>For reference, the formulas are as follows, where X values are the closing
prices and Y values are a straight line 1,2,&hellip;,N.  Variance is the
square of standard deviation (see <a class="pxref" href="#Standard-Deviation">Standard Deviation</a>).
</p>
<div class="example">
<pre class="example-preformatted">         (Covariance X,Y)^2
r^2 = -----------------------
      Variance X * Variance Y

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

lib/App/Chart/doc/chart.html  view on Meta::CPAN

            (EMA[N] of U) + (EMA[N] of D)
</pre></div>

<p>Wilder recommended a smoothing period of N=14, and that&rsquo;s the default in
Chart.  Note also that the period is interpreted by Wilder&rsquo;s reckoning of EMA
smoothing (see <a class="ref" href="#Wilder-EMA-period">Wilder EMA period</a>).
</p>
<p>An index value of 70 is considered overbought and 30 oversold; those levels
are shown as dashed lines.  The principle is that after a large proportion of
movement in one direction, a reaction the other way becomes likely.  On the
other hand it&rsquo;s easy to see from the formula that a steady progressive trend
(every day up, or every day down) can push the RSI to an extreme and hold it
there.
</p>
<p>The term &ldquo;relative strength&rdquo; also refers to a comparison between a stock and
the overall market.  This is sometimes called &ldquo;relative strength
comparative&rdquo; to avoid confusion.  This is unrelated to the relative strength
and relative strength index described in this section.
</p>
<p>See also CMO (see <a class="pxref" href="#Chande-Momentum-Oscillator">Chande Momentum Oscillator</a>) which is an RSI with SMA
smoothing, and TSI (see <a class="pxref" href="#True-Strength-Index">True Strength Index</a>) which is an RSI with

lib/App/Chart/doc/chart.html  view on Meta::CPAN

average of the true range (TR, see <a class="pxref" href="#True-Range">True Range</a>).  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&rsquo;s high less
yesterday&rsquo;s low, compared to a two-day average of the true range (yesterday&rsquo;s
true range and the day before&rsquo;s).  RWI low is similar, but using <em class="math">High[K]
- Low[today]</em> for the movement down from past high to today&rsquo;s low.
</p>
<p>The factor <em class="math">sqrt(K)</em> 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 <em class="math">sqrt(K)</em>.  So the formula compares observed distance in
average day&rsquo;s steps compared to the <em class="math">sqrt(K)</em> 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.
</p>

<hr>
</div>
<div class="section-level-extent" id="Stochastics">
<div class="nav-panel">

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<a class="index-entry-id" id="index-Twiggs-money-flow"></a>
<a class="index-entry-id" id="index-Money-flow_002c-Twiggs"></a>
<a class="index-entry-id" id="index-Index_002c-Twiggs-money-flow"></a>

<p><a class="uref" href="http://www.incrediblecharts.com/technical/twiggs_money_flow.htm">http://www.incrediblecharts.com/technical/twiggs_money_flow.htm</a>
</p>
<a class="index-entry-id" id="index-Twiggs_002c-Colin"></a>
<p>The Twiggs money flow index by Colin Twiggs is a variation of the Chaikin
money flow index (see <a class="pxref" href="#Chaikin-Money-Flow">Chaikin Money Flow</a>) using true range so as to
include gap moves, and using EMA smoothing (see <a class="pxref" href="#Exponential-Moving-Average">Exponential Moving Average</a>) to avoid jumps when a high volume day drops out of the calculation.
The formula is
</p>
<div class="example">
<pre class="example-preformatted">                                /      close - truelow       \
            EMA[N] of  volume * | 2 * ------------------ - 1 |
                                \     truehigh - truelow     /
Twiggs MF = --------------------------------------------------
                  EMA[N] of  volume

truehigh = max (high, prevclose)
truelow  = min (low,  prevclose)

lib/App/Chart/doc/chart.html  view on Meta::CPAN

<p>For a possible fitted line <em class="math">L(X)= a + b*X</em>, the vertical distance
from the line to each point is squared, and a total deviation formed.
</p>
<div class="example">
<pre class="example-preformatted">SumSquares = (y1 - L(x1))^2 + ... + (yN - L(xN))^2
</pre></div>

<p>The line parameters <em class="math">a</em> and <em class="math">b</em> are then chosen to make SumSquares
as small as possible (hence the name &ldquo;least squares&rdquo;), and there&rsquo;s just one
line with that smallest SumSquares.  The calculation is made easier if the X
coordinates are shifted so that <em class="math">Mean(X)=0</em>.  With that the formulas for
<em class="math">a</em> and <em class="math">b</em> are
</p>
<div class="example">
<pre class="example-preformatted">             y1 + ... + yN
a = Mean Y = -------------
                   N

    x1*y1 + ... + xN*yN
b = -------------------
      x1^2 + ... xN^2

lib/App/Chart/doc/chart.html  view on Meta::CPAN

a data set deviate from their average (mean).  The stddev of a past N days is
used in the calculation of Bollinger bands (see <a class="pxref" href="#Bollinger-Bands">Bollinger Bands</a>) and VIDYA
and <a class="ref" href="#Variable-Index-Dynamic-Average">Variable Index Dynamic Average</a>).
</p>
<p>The raw stddev values can be shown in Chart as an indicator, to see what goes
into those calculations.  The values have little direct use though, and for
that reason stddev is under &ldquo;Low Priority&rdquo; in the indicator lists.
</p>
<a class="index-entry-id" id="index-Quadratic-mean-1"></a>
<a class="index-entry-id" id="index-Mean_002c-quadratic-1"></a>
<p>For reference, the formula on prices p1 to pN is as follows.  Each
<em class="math">p[i]-m</em> is the distance from the mean <em class="math">m</em>, and those distances
are averaged with a quadratic mean.
</p>
<div class="example">
<pre class="example-preformatted">               / (p1-m)^2 + (p2-m)^2 + ... + (pN-m)^2 \
Stddev = sqrt (  ------------------------------------  )
               \                   N                  /
</pre></div>

<p>where <em class="math">m</em> is the arithmetic mean
</p>
<div class="example">
<pre class="example-preformatted">    p1 + p2 + ... + pN
m = ------------------
            N
</pre></div>

<p>Also, for reference, the formula can be rearranged to the following form,
&ldquo;sum of the squares minus square of the sums&rdquo;.  This is what Chart uses,
because a new term can be shifted into the sums without recalculating all N
terms.
</p>
<div class="example">
<pre class="example-preformatted">               / p1^2 + p2^2 + ... + pN^2   (p1 + p2 + ... + pN)^2 \
Stddev = sqrt (  ------------------------ - ----------------------  )
               \            N                         N^2          /
</pre></div>

lib/App/Chart/doc/chart.html  view on Meta::CPAN


<a class="index-entry-id" id="index-example_002eses"></a>
<p><code class="code">chart-latest</code> above can be used in SES (see <a data-manual="ses" href="https://www.gnu.org/software/emacs/manual/html_mono/ses.html#Top">Simple Emacs
Spreadsheet</a> in <cite class="cite">Simple Emacs
Spreadsheet</cite>) expressions to include prices in a portfolio etc.  See
<samp class="file">emacs/example.ses</samp> in the Chart sources for a sample spreadsheet doing
this.
</p>
<p>Since <code class="code">chart-latest</code> doesn&rsquo;t download new data an
<kbd class="kbd">M-x ses-recalculate-all</kbd> just shows existing downloaded quotes
(see <a data-manual="ses" href="https://www.gnu.org/software/emacs/manual/html_mono/ses.html#Formulas">Cell formulas</a> in <cite class="cite">SES: Simple
Emacs Spreadsheet</cite>).
</p>
<a class="index-entry-id" id="index-chart_002dses_002drefresh"></a>
<p><kbd class="kbd">M-x chart-ses-refresh</kbd> does a combination <code class="code">ses-recalculate-all</code> and
download of Chart prices used.  A first recalculate records calls to
<code class="code">chart-latest</code> for which prices are used in the spreadsheet, they&rsquo;re
downloaded, then a second recalculate applies the new data.  (Further rounds
of download and recalculate are done as necessary if conditionals in
expressions use yet more symbols.)
</p>



( run in 0.984 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )