| 1 | package Finance::GeniusTrader::Indicators::Generic::Divide; | ||
| 2 | |||
| 3 | # Copyright 2003 Oliver Bossert | ||
| 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 | use Finance::GeniusTrader::Tools qw(:math); | ||
| 15 | use Finance::GeniusTrader::ArgsTree; | ||
| 16 | |||
| 17 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 18 | @NAMES = ("Divide[#*]"); | ||
| 19 | @DEFAULT_ARGS = (); | ||
| 20 | |||
| 21 | =head1 NAME | ||
| 22 | |||
| 23 | Finance::GeniusTrader::Indicators::Generic::Divide - Calculates Param1 / Param2 | ||
| 24 | |||
| 25 | =head1 DESCRIPTION | ||
| 26 | |||
| 27 | This Indicator is calculation an division of several parameters. | ||
| 28 | |||
| 29 | =head2 Overview | ||
| 30 | |||
| 31 | =head2 Calculation | ||
| 32 | |||
| 33 | =head2 Examples | ||
| 34 | |||
| 35 | =head2 Links | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | sub initialize { | ||
| 40 | my ($self) = @_; | ||
| 41 | for (my $j = 1; $j <= $self->{'args'}->get_nb_args; $j++) { | ||
| 42 | unless ($self->{'args'}->is_constant($j)) { | ||
| 43 | $self->add_arg_dependency($j, 1); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | } | ||
| 48 | |||
| 49 | sub calculate { | ||
| 50 | my ($self, $calc, $i) = @_; | ||
| 51 | my $indic = $calc->indicators; | ||
| 52 | |||
| 53 | return if ($calc->indicators->is_available($self->get_name, $i)); | ||
| 54 | |||
| 55 | return if (! $self->check_dependencies($calc, $i)); | ||
| 56 | |||
| 57 | my $value = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 58 | return if (! defined($value) ); | ||
| 59 | |||
| 60 | my $div; | ||
| 61 | for (my $j = 2; $j <= $self->{'args'}->get_nb_args; $j++) | ||
| 62 | { | ||
| 63 | $div = $self->{'args'}->get_arg_values($calc, $i, $j); | ||
| 64 | $value /= $div unless ($div == 0); | ||
| 65 | } | ||
| 66 | $indic->set($self->get_name, $i, $value); | ||
| 67 | } | ||
| 68 | |||
| 69 | |||
| 70 | 1; |