| 1 | package Finance::GeniusTrader::Signals::Indicators::RSIUp; | ||
| 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); | ||
| 9 | |||
| 10 | use Finance::GeniusTrader::Signals; | ||
| 11 | use Finance::GeniusTrader::Prices; | ||
| 12 | use Finance::GeniusTrader::Indicators::RSI; | ||
| 13 | |||
| 14 | @ISA = qw(Finance::GeniusTrader::Signals); | ||
| 15 | @NAMES = ("RSIUp[#1,#2]"); | ||
| 16 | |||
| 17 | =head1 Finance::GeniusTrader::Signals::Indicators::RSIDown | ||
| 18 | |||
| 19 | Signal when we cross up a limit on the RSI. Limit is 30 by default. | ||
| 20 | |||
| 21 | =cut | ||
| 22 | sub new { | ||
| 23 | my $type = shift; | ||
| 24 | my $class = ref($type) || $type; | ||
| 25 | my $args = shift; | ||
| 26 | |||
| 27 | my $self = { "args" => defined($args) ? $args : [30, 14] }; | ||
| 28 | $self->{'args'}[1] = 14 if (! defined($self->{'args'}[1])); | ||
| 29 | |||
| 30 | return manage_object(\@NAMES, $self, $class, $self->{'args'}, ""); | ||
| 31 | } | ||
| 32 | |||
| 33 | sub initialize { | ||
| 34 | my ($self) = @_; | ||
| 35 | |||
| 36 | $self->{'rsi'} = Finance::GeniusTrader::Indicators::RSI->new([ $self->{'args'}[1] ]); | ||
| 37 | |||
| 38 | $self->add_indicator_dependency($self->{'rsi'}, 2); | ||
| 39 | } | ||
| 40 | |||
| 41 | sub detect { | ||
| 42 | my ($self, $calc, $i) = @_; | ||
| 43 | my $indic = $calc->indicators; | ||
| 44 | my $limit = $self->{'args'}[0]; | ||
| 45 | my $rsiname = $self->{'rsi'}->get_name; | ||
| 46 | my $name = $self->get_name; | ||
| 47 | |||
| 48 | return if ($calc->signals->is_available($name, $i)); | ||
| 49 | return if (! $self->check_dependencies($calc, $i)); | ||
| 50 | |||
| 51 | # Test if we have crossed the 30 limit | ||
| 52 | if ( # RSI of $i-1 <= 30 | ||
| 53 | $indic->get($rsiname, $i - 1) <= $limit && | ||
| 54 | |||
| 55 | # RSI of $i > 30 | ||
| 56 | $indic->get($rsiname, $i) > $limit | ||
| 57 | ) | ||
| 58 | { | ||
| 59 | $calc->signals->set($name, $i, 1); | ||
| 60 | } else { | ||
| 61 | $calc->signals->set($name, $i, 0); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | 1; |