GeniusTrader/Systems/SMA.pm untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 77 CC 4 SCAR 16.4
CC
4
Cov
0%
long_signal
12.0
new
6.0
initialize
2.0
CRAP 5.2
1 package Finance::GeniusTrader::Systems::SMA;
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::Prices;
11 use Finance::GeniusTrader::Systems;
12 use Finance::GeniusTrader::Indicators::SMA;
13  
14 @ISA = qw(Finance::GeniusTrader::Systems);
15 @NAMES = ("SMA[#1,#2,#3]");
16  
17 =pod
18  
19 =head1 Stochastic
20  
21 =cut
22  
23 sub new {
24 my $type = shift;
25 my $class = ref($type) || $type;
26 my $args = shift;
27  
28 my $self = { "args" => defined($args) ? $args : [5, 20, 10] };
29  
30 return manage_object(\@NAMES, $self, $class, $self->{'args'}, "");
31 }
32  
33 sub initialize {
34 my ($self) = @_;
35  
36 $self->{'sma1'} = Finance::GeniusTrader::Indicators::SMA->new([ $self->{'args'}[0] ]);
37 $self->{'sma2'} = Finance::GeniusTrader::Indicators::SMA->new([ $self->{'args'}[1] ]);
38 $self->{'sma3'} = Finance::GeniusTrader::Indicators::SMA->new([ $self->{'args'}[2] ]);
39  
40 $self->{'allow_multiple'} = 0;
41  
42 $self->add_indicator_dependency($self->{'sma1'}, 2);
43 $self->add_indicator_dependency($self->{'sma2'}, 2);
44 $self->add_indicator_dependency($self->{'sma3'}, 2);
45 }
46  
47  
48 sub long_signal {
49 my ($self, $calc, $i) = @_;
50 my $indic = $calc->indicators;
51
52 return 0 if (!$self->check_dependencies($calc, $i));
53
54 if ( ( $indic->get($self->{'sma1'}->get_name, $i - 1) <
55 $indic->get($self->{'sma2'}->get_name, $i - 1)) &&
56 ( $indic->get($self->{'sma1'}->get_name, $i) >
57 $indic->get($self->{'sma2'}->get_name, $i) )
58 )
59 {
60 return 1;
61 }
62 return 0;
63 }
64  
65 sub short_signal {
66 my ($self, $calc, $i) = @_;
67 my $indic = $calc->indicators;
68
69 return 0;
70 }