| 1 | package Finance::GeniusTrader::Indicators::ForceIndex; | ||
| 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); | ||
| 9 | |||
| 10 | use Finance::GeniusTrader::Indicators; | ||
| 11 | use Finance::GeniusTrader::Prices; | ||
| 12 | |||
| 13 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 14 | @NAMES = ("ForceIndex"); | ||
| 15 | |||
| 16 | =head1 Finance::GeniusTrader::Indicators::ForceIndex | ||
| 17 | |||
| 18 | Finance::GeniusTrader::Indicators::ForceIndex->new() | ||
| 19 | |||
| 20 | =head2 INFORMATION | ||
| 21 | |||
| 22 | The force index itself varies too much. To be of any use, you'd better | ||
| 23 | use a 2 days exponential moving average of it. | ||
| 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->add_prices_dependency(2); | ||
| 33 | } | ||
| 34 | |||
| 35 | sub calculate { | ||
| 36 | my ($self, $calc, $i) = @_; | ||
| 37 | my $indic = $calc->indicators; | ||
| 38 | my $prices = $calc->prices; | ||
| 39 | my $name = $self->get_name; | ||
| 40 | |||
| 41 | return if ($indic->is_available($name, $i)); | ||
| 42 | return if (! $self->check_dependencies($calc, $i)); | ||
| 43 | |||
| 44 | my $val = $prices->at($i)->[$VOLUME] * | ||
| 45 | ($prices->at($i)->[$CLOSE] - $prices->at($i - 1)->[$CLOSE]); | ||
| 46 | $indic->set($name, $i, $val); | ||
| 47 | } | ||
| 48 | |||
| 49 | 1; |