| 1 | package Finance::GeniusTrader::Signals::Prices::Advance; | ||
| 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 | use strict; | ||
| 8 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 9 | |||
| 10 | # Standards-Version: 1.0 | ||
| 11 | |||
| 12 | use Finance::GeniusTrader::Signals; | ||
| 13 | use Finance::GeniusTrader::Prices; | ||
| 14 | |||
| 15 | @ISA = qw(Finance::GeniusTrader::Signals); | ||
| 16 | @NAMES = ("Advance[#1]"); | ||
| 17 | @DEFAULT_ARGS = (0); | ||
| 18 | |||
| 19 | =head1 NAME | ||
| 20 | |||
| 21 | Finance::GeniusTrader::Signals::Advance | ||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | The Advance Signal will be able to tell you if a security is advancing more than x % or not from the previous period. | ||
| 26 | Advance, Decline and Unchange Signals are basics signals and will be your row materials for designing lots of market indicators. | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | sub initialize { | ||
| 31 | my ($self) = @_; | ||
| 32 | |||
| 33 | $self->add_prices_dependency(2); | ||
| 34 | } | ||
| 35 | |||
| 36 | sub detect { | ||
| 37 | my ($self, $calc, $i) = @_; | ||
| 38 | my $q = $calc->prices; | ||
| 39 | my $percentage = ($self->{'args'}->get_arg_values($calc, $i, 1) / 100); | ||
| 40 | |||
| 41 | return if ($calc->signals->is_available($self->get_name, $i)); | ||
| 42 | return if (! $self->check_dependencies($calc, $i)); | ||
| 43 | |||
| 44 | # We're moving up ! | ||
| 45 | if ( $q->at($i)->[$LAST] > ($q->at($i-1)->[$LAST] * ( 1 + $percentage))) { | ||
| 46 | $calc->signals->set($self->get_name, $i, 1); | ||
| 47 | } else { | ||
| 48 | $calc->signals->set($self->get_name, $i, 0); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | 1; |