| 1 | package Finance::GeniusTrader::Indicators::Generic::SumDownDiffs; | ||
| 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 = ("SumDownDiffs[#*]"); | ||
| 19 | @DEFAULT_ARGS = (14, "{I:Prices CLOSE}"); | ||
| 20 | |||
| 21 | =head1 NAME | ||
| 22 | |||
| 23 | Finance::GeniusTrader::Indicators::Generic::SumDownDiffs - Calculation of the Sum of the last n days when the price goes down | ||
| 24 | |||
| 25 | =head1 DESCRIPTION | ||
| 26 | |||
| 27 | Calculates the Sum of the difference of the last n days when the price goes down. | ||
| 28 | |||
| 29 | =head2 Overview | ||
| 30 | |||
| 31 | =head2 Calculation | ||
| 32 | |||
| 33 | =head2 Examples | ||
| 34 | |||
| 35 | Finance::GeniusTrader::Indicators::Generic::SumDownDiffs->new() | ||
| 36 | |||
| 37 | =head2 Links | ||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | sub initialize { | ||
| 42 | my ($self) = @_; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub calculate { | ||
| 46 | my ($self, $calc, $i) = @_; | ||
| 47 | my $nb = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 48 | my $name = $self->get_name; | ||
| 49 | my $sum = 0; | ||
| 50 | my $yesterday; | ||
| 51 | my $today; | ||
| 52 | |||
| 53 | return if (! defined($nb)); | ||
| 54 | |||
| 55 | $self->remove_volatile_dependencies(); | ||
| 56 | $self->add_volatile_arg_dependency(2, $nb); | ||
| 57 | |||
| 58 | return if ($calc->indicators->is_available($name, $i)); | ||
| 59 | return if (! $self->check_dependencies($calc, $i)); | ||
| 60 | |||
| 61 | $yesterday = $self->{'args'}->get_arg_values($calc, $i-$nb, 2); | ||
| 62 | |||
| 63 | return if (! defined($yesterday)); | ||
| 64 | for(my $n = $i - $nb + 1; $n <= $i; $n++) | ||
| 65 | { | ||
| 66 | $today = $self->{'args'}->get_arg_values($calc, $n, 2); | ||
| 67 | if ($today < $yesterday ) { | ||
| 68 | $sum += -($today - $yesterday); | ||
| 69 | } | ||
| 70 | $yesterday = $today; | ||
| 71 | } | ||
| 72 | $calc->indicators->set($name, $i, $sum); | ||
| 73 | } | ||
| 74 | |||
| 75 | 1; |