GeniusTrader/Signals/Indicators/RSIDown.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 71 CC 6 SCAR 22.9
CC
6
Cov
0%
detect
20.0
new
12.0
initialize
2.0
CRAP 9.8
1 package Finance::GeniusTrader::Signals::Indicators::RSIDown;
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 = ("RSIDown[#1,#2]");
16  
17 =head1 Finance::GeniusTrader::Signals::Indicators::RSIDown
18  
19 Signal when we cross down a limit on the RSI. Limit is 70 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 : [70, 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 70 limit
52 if ( # RSI of $i-1 >= 70
53 $indic->get($rsiname, $i - 1) >= $limit &&
54  
55 # RSI of $i < 70
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;