| 1 | package Finance::GeniusTrader::Indicators::ADL; | ||
| 2 | |||
| 3 | # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber | ||
| 4 | # This file is distributed under the terms of the General Public License | ||
| 5 | # version 2 or (at your option) any later version. | ||
| 6 | |||
| 7 | # Standards-Version: 1.0 | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 11 | |||
| 12 | use Finance::GeniusTrader::Indicators; | ||
| 13 | use Finance::GeniusTrader::Prices; | ||
| 14 | |||
| 15 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 16 | @NAMES = ("ADL[#*]"); | ||
| 17 | @DEFAULT_ARGS = ("{I:Prices HIGH}", "{I:Prices LOW}", "{I:Prices VOLUME}", "{I:Prices CLOSE}"); | ||
| 18 | |||
| 19 | =head1 NAME | ||
| 20 | |||
| 21 | Finance::GeniusTrader::Indicators::ADL - Accumulation/Distribution line | ||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | =head2 Overview | ||
| 26 | |||
| 27 | The Accumulation/Distribution Line was developed by Marc Chaikin to assess the cumulative flow of money into and out of a security. | ||
| 28 | |||
| 29 | =head2 Calculation | ||
| 30 | |||
| 31 | The ADL is the cumulative sum of (((Close - Low) - (High - Close)) / (High - Low)) * Volume | ||
| 32 | |||
| 33 | =head2 Links | ||
| 34 | |||
| 35 | http://www.stockcharts.com/education/What/IndicatorAnalysis/indic_AccumDistLine.html | ||
| 36 | http://www.equis.com/free/taaz/accumdistr.html | ||
| 37 | |||
| 38 | =cut | ||
| 39 | sub initialize { | ||
| 40 | my $self = shift; | ||
| 41 | $self->add_arg_dependency(1,1); | ||
| 42 | $self->add_arg_dependency(2,1); | ||
| 43 | $self->add_arg_dependency(3,1); | ||
| 44 | $self->add_arg_dependency(4,1); | ||
| 45 | } | ||
| 46 | |||
| 47 | sub calculate { | ||
| 48 | my ($self, $calc, $i) = @_; | ||
| 49 | my $name = $self->get_name; | ||
| 50 | my $adl = 0; | ||
| 51 | my $ad = 0; | ||
| 52 | |||
| 53 | return if ($calc->indicators->is_available($name, $i)); | ||
| 54 | return if (! $self->check_dependencies($calc, $i)); | ||
| 55 | |||
| 56 | my $prices = $calc->prices; | ||
| 57 | my $high = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 58 | my $low = $self->{'args'}->get_arg_values($calc, $i, 2); | ||
| 59 | my $close = $self->{'args'}->get_arg_values($calc, $i, 4); | ||
| 60 | my $vol = $self->{'args'}->get_arg_values($calc, $i, 3); | ||
| 61 | |||
| 62 | if ($calc->indicators->is_available($name, $i - 1)) { | ||
| 63 | $adl = $calc->indicators->get($name, $i - 1); | ||
| 64 | if ($high != $low) { | ||
| 65 | $ad = ((($close - $low) - ($high - $close)) / ($high - $low)) * $vol; | ||
| 66 | } | ||
| 67 | $adl += $ad; | ||
| 68 | $calc->indicators->set($name, $i, $adl); | ||
| 69 | } else { | ||
| 70 | for(my $n = 0; $n <= $i; $n++) | ||
| 71 | { | ||
| 72 | $high = $self->{'args'}->get_arg_values($calc, $n, 1); | ||
| 73 | $low = $self->{'args'}->get_arg_values($calc, $n, 2); | ||
| 74 | $close = $self->{'args'}->get_arg_values($calc, $n, 4); | ||
| 75 | $vol = $self->{'args'}->get_arg_values($calc, $n, 3); | ||
| 76 | |||
| 77 | if ($high != $low) { | ||
| 78 | $ad = ((($close - $low) - ($high - $close)) / ($high - $low)) * $vol; | ||
| 79 | } | ||
| 80 | $adl += $ad; | ||
| 81 | $calc->indicators->set($name, $n, $adl); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | sub calculate_interval { | ||
| 87 | my ($self, $calc, $first, $last) = @_; | ||
| 88 | |||
| 89 | $self->calculate($calc, $last); | ||
| 90 | } | ||
| 91 | |||
| 92 | 1; |