GeniusTrader/Systems/MacdDiff.pm untested

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