| 1 | package Finance::GeniusTrader::Indicators::ElderRay; | ||
| 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 | use strict; | ||
| 8 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 9 | |||
| 10 | use Finance::GeniusTrader::Indicators; | ||
| 11 | use Finance::GeniusTrader::Indicators::EMA; | ||
| 12 | use Finance::GeniusTrader::Prices; | ||
| 13 | |||
| 14 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 15 | @NAMES = ("BullPower[#1]", "BearPower[#1]"); | ||
| 16 | @DEFAULT_ARGS = (13); | ||
| 17 | |||
| 18 | |||
| 19 | =head1 Finance::GeniusTrader::Indicators::ElderRay | ||
| 20 | |||
| 21 | Finance::GeniusTrader::Indicators::ElderRay->new([13]) | ||
| 22 | |||
| 23 | =head2 INFORMATION | ||
| 24 | |||
| 25 | It has been invented by Alexander Elder, and it is explained in his book | ||
| 26 | "Trading for a living" ("Vivre du trading" in french). | ||
| 27 | |||
| 28 | =cut | ||
| 29 | sub initialize { | ||
| 30 | my $self = shift; | ||
| 31 | |||
| 32 | $self->{'mme'} = Finance::GeniusTrader::Indicators::EMA->new([$self->{'args'}->get_arg_names(1)]); | ||
| 33 | $self->add_indicator_dependency($self->{'mme'}, 1); | ||
| 34 | $self->add_prices_dependency(1); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub calculate { | ||
| 38 | my ($self, $calc, $i) = @_; | ||
| 39 | my $indic = $calc->indicators; | ||
| 40 | my $prices = $calc->prices; | ||
| 41 | my $name = $self->get_name; | ||
| 42 | |||
| 43 | return if ($indic->is_available($name, $i)); | ||
| 44 | return if (! $self->check_dependencies($calc, $i)); | ||
| 45 | |||
| 46 | my $bull = $prices->at($i)->[$HIGH] - | ||
| 47 | $indic->get($self->{'mme'}->get_name, $i); | ||
| 48 | my $bear = $prices->at($i)->[$LOW] - | ||
| 49 | $indic->get($self->{'mme'}->get_name, $i); | ||
| 50 | $indic->set($self->get_name(0), $i, $bull); | ||
| 51 | $indic->set($self->get_name(1), $i, $bear); | ||
| 52 | } | ||
| 53 | |||
| 54 | 1; |