MACD

42 views
Skip to first unread message

brew

unread,
Sep 11, 2008, 7:00:58 PM9/11/08
to stockmonkey
I'm trying to use Math::Business::MACD but so far, it doesn't seem to
output numbers that make sense to me.

For the input to $macd->insert( @closing_values ); I pass in the
@closing_values array, an array of prices for at least 34 periods. Is
the first element the most recent close or is the last element the
most recent close?

Neither way seems to output numbers that make sense, though.....

I notice your list in the example is 38 elements, are extra elements
in the list ignored?

I'm pulling data from my database and walking through it, but maybe I
have to get my code working and outputting data that makes sense at
just at one point first!

brew

Paul Miller

unread,
Sep 12, 2008, 7:01:03 AM9/12/08
to stockmonkey


On Sep 11, 7:00 pm, brew <brew.theM...@gmail.com> wrote:
> I'm trying to use Math::Business::MACD but so far, it doesn't seem to
> output numbers that make sense to me.

That's pretty typical. Hopefully you're not comparing the results to
your favorite site... The results may vary slightly as I've coded to
to match Apple's original ideas and not any specific implementation on
the web.

> For the input to $macd->insert( @closing_values ); I pass in the
> @closing_values array, an array of prices for at least 34 periods.  Is
> the first element the most recent close or is the last element the
> most recent close?

> I'm pulling data from my database and walking through it, but maybe I
> have to get my code working and outputting data that makes sense at
> just at one point first!

Although you can insert all the numbers at once, that's not the way
it's intended to be used, particularly if you're using a database.
The flow should look more like this:

my $pull = $dbh->prepare("select close,closing_date from tablename
where symbol=? order by closing_date");
my $push = $dbh->prepare("update tablename set macd=?, fast=?, slow=?,
trigger=? where symbol=? and closing_date=?");

$pull->execute("IBM") or die $dbh->errstr;

while( my ($close, $date) = $pull->fetchrow_array ) {
$macd->insert($close);

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

next unless defined $macd[0];
# not defined until you have enough data
# in the $macd to calculate the @macd

$push->execute( @macd[0..3], "IBM", $date) or die $dbh->errstr;
# or make your graph or whatever...
}

> Neither way seems to output numbers that make sense, though.....

What's wrong with them?

> I notice your list in the example is 38 elements, are extra elements
> in the list ignored?

Nope. They're inserted left to right order (shifted off the left
site) just as iff you had called insert() like this:

$macd->insert($_) for @values;

Brew Schiller

unread,
Sep 12, 2008, 12:21:45 PM9/12/08
to stock...@googlegroups.com
Paul......

>> I'm trying to use Math::Business::MACD but so far, it doesn't seem to
>> output numbers that make sense to me.
>
> That's pretty typical. Hopefully you're not comparing the results to
> your favorite site... The results may vary slightly as I've coded to
> to match Apple's original ideas and not any specific implementation on
> the web.

I expected the numbers may vary slightly from the sites I use, but my
numbers were completely different, sometimes the wrong polarity and
other times trending the wrong way.

I'll have to experiment around with it some more next week..... I'll
try inserting the data a little at a time, updating as I go. I had
been calculating it point by point, throwing all the data out after
each point.

I'll try it again next week following your db flow update scheme....

Thanks for the info and your comments.

brew
--

Strange Brew (br...@theMode.com)

Check out my Stock Option website http://www.callpix.com
and my Musicians Free Classified http://www.TheMode.com

Paul Miller

unread,
Sep 12, 2008, 12:58:20 PM9/12/08
to stockmonkey


On Sep 12, 12:21 pm, "Brew Schiller" <brew.them...@gmail.com> wrote:
> I expected the numbers may vary slightly from the sites I use, but my
> numbers were completely different, sometimes the wrong polarity and
> other times trending the wrong way.

It will happen that different sites calculating the MACD differently
will signal buy-sell conditions at totally different times...

Let me know how your future results turn out. As far as I know the
MACD module calculates the MACD correctly based on Apple's formulae.
Further, the graphs seem to mostly match up with my favorite sites. ;)
Reply all
Reply to author
Forward
0 new messages