| 1 | package Finance::GeniusTrader::Indicators::Generic::PeriodAgo; | ||
| 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 | # 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(:generic); | ||
| 15 | |||
| 16 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 17 | @NAMES = ("PeriodAgo[#*]"); | ||
| 18 | @DEFAULT_ARGS = (1, "{I:Prices CLOSE}"); | ||
| 19 | |||
| 20 | =head1 NAME | ||
| 21 | |||
| 22 | Finance::GeniusTrader::Indicators::Generic::PeriodAgo - Return data from some periods ago | ||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | This function returns N-Period Ago value of the indicator given on | ||
| 27 | arguments. Without indicator, the close price is used. | ||
| 28 | |||
| 29 | =head1 EXAMPLES | ||
| 30 | |||
| 31 | The high of 3 days ago : | ||
| 32 | |||
| 33 | I:Generic:PeriodAgo 3 {I:Prices HIGH} | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | sub calculate { | ||
| 38 | my ($self, $calc, $i) = @_; | ||
| 39 | my $period = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 40 | my $name = $self->get_name; | ||
| 41 | |||
| 42 | return if ($calc->indicators->is_available($name, $i)); | ||
| 43 | |||
| 44 | $self->remove_volatile_dependencies(); | ||
| 45 | $self->add_volatile_arg_dependency(2, $period); | ||
| 46 | |||
| 47 | return if (! $self->check_dependencies($calc, $i)); | ||
| 48 | |||
| 49 | my $value = $self->{'args'}->get_arg_values($calc, $i - $period, 2); | ||
| 50 | $calc->indicators->set($name, $i, $value); | ||
| 51 | } | ||
| 52 | |||
| 53 | 1; |