« GeniusTrader/Signals/Graphical/CandleSticks/InvertedHammer.pm
↑ Summary
GeniusTrader/Indicators/Generic/Speed.pm »
| 1 | package Finance::GeniusTrader::Indicators::Generic::Diff; | ||
| 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 = ("Diff[#*]"); | ||
| 19 | @DEFAULT_ARGS = ("{I:Prices CLOSE}", 1); | ||
| 20 | |||
| 21 | =head1 NAME | ||
| 22 | |||
| 23 | Finance::GeniusTrader::Indicators::Generic::Diff - Difference between two days | ||
| 24 | |||
| 25 | =head1 DESCRIPTION | ||
| 26 | |||
| 27 | Calculates the difference between the actual value and the value n | ||
| 28 | days ago. | ||
| 29 | |||
| 30 | =over | ||
| 31 | |||
| 32 | =item {I:RSI} 14 | ||
| 33 | |||
| 34 | =back | ||
| 35 | |||
| 36 | =cut | ||
| 37 | |||
| 38 | sub initialize { | ||
| 39 | my ($self) = @_; | ||
| 40 | } | ||
| 41 | |||
| 42 | sub calculate { | ||
| 43 | my ($self, $calc, $i) = @_; | ||
| 44 | my $name = $self->get_name; | ||
| 45 | my $value; | ||
| 46 | |||
| 47 | return if ($calc->indicators->is_available($name, $i)); | ||
| 48 | |||
| 49 | my $nb = $self->{'args'}->get_arg_values($calc, $i, 2); | ||
| 50 | if ( defined($nb) ) { | ||
| 51 | my $present = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 52 | my $past = $self->{'args'}->get_arg_values($calc, $i-$nb, 1); | ||
| 53 | $value = $present - $past; | ||
| 54 | } | ||
| 55 | |||
| 56 | if ( defined($value) ) { | ||
| 57 | $calc->indicators->set($name, $i, $value); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | 1; |