GeniusTrader/Signals/Graphical/CandleSticks/BullishHarami.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 83 CC 5 SCAR 21.6
CC
5
Cov
0%
detect
20.0
new
6.0
initialize
2.0
CRAP 8.7
1 package Finance::GeniusTrader::Signals::Graphical::CandleSticks::BullishHarami;
2  
3 # Copyright (C) 2007 M.K.Pai
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  
19 use strict;
20 use vars qw(@ISA @NAMES);
21  
22 use Finance::GeniusTrader::Signals;
23 use Finance::GeniusTrader::Prices;
24 use Finance::GeniusTrader::Indicators::CNDL;
25  
26 @ISA = qw(Finance::GeniusTrader::Signals);
27 @NAMES = ("BullishHarami");
28  
29 =head1 Finance::GeniusTrader::Signals::Graphical::CandleSticks::BullishHarami
30  
31 =head2 Overview
32  
33 The Bullish Harami signifies a decrease of momentum. It occurs when a
34 small bullish (empty) line occurs after a large bearish (filled)
35 line in such a way that close of the bullish line is above the open
36 of the bearish line and the open of the bullish line is lower than the
37 close of the bearish line.
38  
39 The Bullish Harami is a mirror image of the Bearish Engulfing Line.
40  
41 =head2 Construction
42  
43 If yesterday closed higher, a Bullish Harami will form when today's open
44 is above yesterday's close and today's close is above yesterday's open.
45  
46 =head2 Representation
47  
48 |
49 ###
50 ### _|_
51 ### | |
52 ### |___|
53 ### |
54 ###
55 |
56  
57 Bullish Harami
58  
59 =head2 Links
60  
61 1. More information about the bullish harami on Page 33 of the book
62 "Candlestick Charting Explained" by Gregory L. Morris. Morris says that
63 this pattern suggests a trend change.
64  
65 2. Steve Nison also says that the Harami Patterns suggest a trend
66 change. This is on page 80 of his book "Japanese Candlesticks Charting
67 Techniques".
68  
69 3. http://www.equis.com/Customer/Resources/TAAZ/.
70  
71 =cut
72  
73 sub new {
74 my $type = shift;
75 my $class = ref($type) || $type;
76 my $args = shift;
77  
78 my $self = { "args" => defined($args) ? $args : [] };
79
80 return manage_object(\@NAMES, $self, $class, $self->{'args'}, "");
81 }
82  
83 sub initialize {
84 my ($self) = @_;
85
86 $self->{'cndl'} = Finance::GeniusTrader::Indicators::CNDL->new($self->{'args'});
87  
88 $self->add_indicator_dependency($self->{'cndl'}, 2);
89 }
90  
91 sub detect {
92 my ($self, $calc, $i) = @_;
93 my $prices = $calc->prices;
94 my $cndl_name = $self->{'cndl'}->get_name(0);
95 my $bullish_harami_name = $self->get_name(0);;
96  
97 return if ($calc->signals->is_available($self->get_name(0), $i));
98 return if (! $self->check_dependencies($calc, $i));
99
100 my $previous_cndl_code = $calc->indicators->get($cndl_name, $i - 1);
101 my $cndl_code = $calc->indicators->get($cndl_name, $i);
102  
103 # Previous CandleCode from 0 to 15
104 # CandleCode from 80 to 111
105 if (($previous_cndl_code >= 0) and ($previous_cndl_code <= 15) and
106 ($cndl_code >= 80) and ($cndl_code <= 111) and
107 ($prices->at($i)->[$OPEN] > $prices->at($i - 1)->[$CLOSE]) and
108 ($prices->at($i)->[$CLOSE] < $prices->at($i - 1)->[$OPEN])
109 )
110 {
111 $calc->signals->set($bullish_harami_name, $i, 1);
112 } else {
113 $calc->signals->set($bullish_harami_name, $i, 0);
114 }
115 }
116  
117 1;