| 1 | package Finance::GeniusTrader::Signals::Generic::Decrease; | ||
| 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); | ||
| 11 | |||
| 12 | use Finance::GeniusTrader::Signals; | ||
| 13 | use Finance::GeniusTrader::Eval; | ||
| 14 | use Finance::GeniusTrader::Tools qw(:generic); | ||
| 15 | |||
| 16 | @ISA = qw(Finance::GeniusTrader::Signals); | ||
| 17 | @NAMES = ("Decrease[#*]"); | ||
| 18 | |||
| 19 | =head1 Decrease Generic Signal | ||
| 20 | |||
| 21 | =head2 Overview | ||
| 22 | |||
| 23 | This Generic Signal will be able to tell you when a specific indicator is | ||
| 24 | decreasing from its previous level. | ||
| 25 | |||
| 26 | =head2 EXAMPLE | ||
| 27 | |||
| 28 | You can use this signal to determine if the | ||
| 29 | securities closing price is decreasing | ||
| 30 | |||
| 31 | S:Generic:Decrease {I:Prices CLOSE} | ||
| 32 | |||
| 33 | =cut | ||
| 34 | sub initialize { | ||
| 35 | my ($self) = @_; | ||
| 36 | warn "Bad number of arguments given to S:Generic:Decrease !" if ($self->{'args'}->get_nb_args() != 1); | ||
| 37 | } | ||
| 38 | |||
| 39 | sub detect { | ||
| 40 | my ($self, $calc, $i) = @_; | ||
| 41 | |||
| 42 | return if ($calc->signals->is_available($self->get_name, $i)); | ||
| 43 | return if ($i < 1); | ||
| 44 | |||
| 45 | my $first = $self->{'args'}->get_arg_values($calc, $i - 1, 1); | ||
| 46 | my $second = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 47 | |||
| 48 | return if (not (defined($first) && defined($second))); | ||
| 49 | |||
| 50 | if ($first > $second) { | ||
| 51 | $calc->signals->set($self->get_name, $i, 1); | ||
| 52 | } else { | ||
| 53 | $calc->signals->set($self->get_name, $i, 0); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | 1; |