Math::Business::MACD - Technical Analysis: Moving Average Convergence/Divergence
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 = map { 3+ int rand 27 } 1 .. $slow+$fast; # choose one: $macd->insert( @closing_values ); $macd->insert( $_ ) for @closing_values; print " MACD: ", scalar $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"; my @macd = $macd->query; # $macd[0] is the MACD # $macd[1] is the Fast # $macd[2] is the Slow # $macd[3] is the Trigger # $macd[4] is the Histogram
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.
David Perry
Paul Miller <jettero@cpan.org>
<jettero@cpan.org>
I am using this software in my own projects... If you find bugs, please please please let me know. There is a mailing list with very light traffic that you might want to join: http://groups.google.com/group/stockmonkey/.
Copyright © 2013 Paul Miller
This is released under the Artistic License. See perlartistic.
perl(1), Math::Business::StockMonkey, Math::Business::StockMonkey::FAQ, Math::Business::StockMonkey::CookBook
http://en.wikipedia.org/wiki/MACD
To install Math::Business::DMI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::Business::DMI
CPAN shell
perl -MCPAN -e shell install Math::Business::DMI
For more information on module installation, please visit the detailed CPAN module installation guide.