GeniusTrader/Signals/Swing/Trend.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 33 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 99 CC 5 SCAR 26.9
CC
5
Cov
0%
detect
30.0
new
2.0
initialize
2.0
CRAP 14.7
1 package Finance::GeniusTrader::Signals::Swing::Trend;
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  
13 @ISA = qw(Finance::GeniusTrader::Signals);
14 @NAMES = ("TrendUp", "TrendDown");
15  
16 =pod
17  
18 =head1 Finance::GeniusTrader::Signals::Swing::Trend
19  
20 =cut
21 sub new {
22 my $type = shift;
23 my $class = ref($type) || $type;
24  
25 my $self = { "args" => [] };
26
27 return manage_object(\@NAMES, $self, $class, $self->{'args'}, "");
28 }
29  
30 sub initialize {
31 my ($self) = @_;
32  
33 $self->add_prices_dependency(3);
34 }
35  
36 sub detect {
37 my ($self, $calc, $i) = @_;
38 my $q = $calc->prices;
39 my $name_up = $self->get_name(0);
40 my $name_down = $self->get_name(1);
41  
42 return if ($calc->signals->is_available($name_up, $i));
43 return if (! $self->check_dependencies($calc, $i));
44
45 if ( # New tops each day
46 $q->at($i)->[$HIGH] >= $q->at($i-1)->[$HIGH] &&
47 $q->at($i-1)->[$HIGH] > $q->at($i-2)->[$HIGH] &&
48 # Each bottom is higher
49 $q->at($i)->[$LOW] > $q->at($i-1)->[$LOW] &&
50 $q->at($i-1)->[$LOW] > $q->at($i-2)->[$LOW] &&
51 # The two first candle are white
52 $q->at($i-2)->[$LAST] > $q->at($i-2)->[$FIRST] &&
53 $q->at($i-1)->[$LAST] > $q->at($i-1)->[$FIRST]
54 )
55 {
56 $calc->signals->set($name_up, $i, 1);
57 } else {
58 $calc->signals->set($name_up, $i, 0);
59 }
60  
61 if ( # New bottoms each day
62 $q->at($i)->[$LOW] <= $q->at($i-1)->[$LOW] &&
63 $q->at($i-1)->[$LOW] < $q->at($i-2)->[$LOW] &&
64 # Each top is lower
65 $q->at($i)->[$HIGH] < $q->at($i-1)->[$HIGH] &&
66 $q->at($i-1)->[$HIGH] < $q->at($i-2)->[$HIGH] &&
67 # The two first candle are black
68 $q->at($i-2)->[$LAST] < $q->at($i-2)->[$FIRST] &&
69 $q->at($i-1)->[$LAST] < $q->at($i-1)->[$FIRST]
70 )
71 {
72 $calc->signals->set($name_down, $i, 1);
73 return 1;
74 } else {
75 $calc->signals->set($name_down, $i, 0);
76 }
77 }
78  
79 1;