NAME

Math::Business::MACD - Technical Analysis: Moving Average Convergence/Divergence

SYNOPSIS

use Math::Business::MACD;

# WARNING: To clear up any confusion, Appel used 12-26-9 rather
# than the 26,12,9 shown here -- that is, he used
# fast-slow-trigger instead of slow-fast-trigger as used below.

my ($slow, $fast, $trigger) = (26, 12, 9);
my $macd = new Math::Business::MACD;
   $macd->set_days( $slow, $fast, $trigger );

# alternatively/equivelently
my $macd = new Math::Business::MACD( $slow, $fast, $trigger );

# or to just get the recommended model ... (26,12,9)
my $macd = Math::Business::MACD->recommended;

my @closing_values = qw(
    3 4 4 5 6 5 6 5 5 5 5 
    6 6 6 6 7 7 7 8 8 8 8 
);

# choose one:
$macd->insert( @closing_vlaues );
$macd->insert( $_ ) for @closing_values;

print "       MACD: ", $macd->query,           "\n",
      "Trigger EMA: ", $macd->query_trig_ema,  "\n",
      "   Fast EMA: ", $macd->query_fast_ema,  "\n",
      "   Slow EMA: ", $macd->query_slow_ema,  "\n";
      "  Histogram: ", $macd->query_histogram, "\n";

To avoid recalculating huge lists when you add a few new values on the end:

$ema->start_with( 
    $last_slow_ema,
    $last_fast_ema,
    $last_trig_ema,
);

RESEARCHER

The MACD was designed by Gerald Appel in the 1960s.

MACD graphs usually show:

1. The MACD=ema[fast]-ema[slow] -- query()
2. The signal=ema[trig]         -- query_trig_ema()
3. The histogram=MACD-signal    -- query_histogram()

Appel designed the MACD to spot tend changes.

It is believed that when the MACD crosses the signal line on the way up, it signals a buy condition and when the MACD crosses the signal line on the way down, it's time to sell. The histogram can help to visualize when a crossing is going to occur.

A upward crossing of the MACD through the zero-line indicates a bullish situation and vice versa.

Thanks

David Perry <David.Perry@ca.com>

AUTHOR

Paul Miller <jettero@cpan.org>

I am using this software in my own projects... If you find bugs, please please please let me know.

I normally hang out on #perl on freenode, so you can try to get immediate gratification there if you like. irc://irc.freenode.net/perl

COPYRIGHT

Copyright (c) 2008 Paul Miller -- LGPL [Software::License::LGPL_2_1]

perl -MSoftware::License::LGPL_2_1 \
     -e '$l = Software::License::LGPL_2_1->new({
         holder=>"Paul Miller"});
         print $l->fulltext' | less

SEE ALSO

perl(1)

http://en.wikipedia.org/wiki/MACD