NAME

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

SYNOPSIS

use Math::Business::MACD;

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 );

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";

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,
);

EMA/SMA Note

As of SMA 0.99, EMA 1.06, MACD 1.10, the MACD will now return 
'undef' where there is not yet enough data to calculate the EMAs.
Further, the trigger and histogram values will not be available until
the trigger EMA has enough data.

This is going to be a compat buster for some of my graphs, but it has
to be done for correctness.  :(

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