« GeniusTrader/Indicators/Generic/SumDownDiffs.pm
↑ Summary
GeniusTrader/Signals/Swing/TrendEnding.pm »
| 1 | package Finance::GeniusTrader::Indicators::Generic::SumUpDiffs; | ||
| 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 = ("SumUpDiffs[#*]"); | ||
| 19 | @DEFAULT_ARGS = (14, "{I:Prices CLOSE}"); | ||
| 20 | |||
| 21 | =head1 NAME | ||
| 22 | |||
| 23 | Finance::GeniusTrader::Indicators::Generic::SumUpDiffs - Calculation of the Sum of the differences of the last n days when the price goes up | ||
| 24 | |||
| 25 | =head1 DESCRIPTION | ||
| 26 | |||
| 27 | Calculation of the Sum of the differences of the last n days when the price goes up. | ||
| 28 | |||
| 29 | =head2 Overview | ||
| 30 | |||
| 31 | =head2 Calculation | ||
| 32 | |||
| 33 | =head2 Examples | ||
| 34 | |||
| 35 | Finance::GeniusTrader::Indicators::Generic::SumUpDiffs->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 | return if (! defined($yesterday)); | ||
| 63 | for(my $n = $i - $nb + 1; $n <= $i; $n++) | ||
| 64 | { | ||
| 65 | $today = $self->{'args'}->get_arg_values($calc, $n, 2); | ||
| 66 | if ($today > $yesterday ) { | ||
| 67 | $sum += $today - $yesterday; | ||
| 68 | } | ||
| 69 | $yesterday = $today; | ||
| 70 | } | ||
| 71 | $calc->indicators->set($name, $i, $sum); | ||
| 72 | } | ||
| 73 | |||
| 74 | 1; |