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

filter: Statementstmt 0.0% 0 / 39 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 / 84 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::BearishHarami;
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 = ("BearishHarami");
28  
29 =head1 Finance::GeniusTrader::Signals::Graphical::CandleSticks::BearishHarami
30  
31 =head2 Overview
32  
33 The Bearish Harami signifies a decrease of momentum. It occurs when a
34 small bearish (filled-in) line occurs after a large bullish (empty)
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 Bearish Harami is a mirror image of the Bullish Engulfing Line.
40  
41  
42 =head2 Construction
43  
44 If yesterday closed higher, a Bearish Harami will form when today's open
45 is below yesterday's closed and today's close is above yesterday's open.
46  
47 =head2 Representation
48  
49 _|_
50 | |
51 | | |
52 | | ###
53 | | ###
54 | | |
55 |___|
56 |
57  
58 Bearish Harami
59  
60 =head2 References
61  
62 1. More information about the bearish harami on Page 33 of the book
63 "Candlestick Charting Explained" by Gregory L. Morris. Morris says that
64 this pattern suggests a trend change.
65  
66 2. Steve Nison also says that the Harami Patterns suggest a trend
67 change. This is on page 80 of his book "Japanese Candlesticks Charting
68 Techniques".
69  
70 3. http://www.equis.com/Customer/Resources/TAAZ/.
71  
72 =cut
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 $self->add_prices_dependency(2);
90 }
91  
92 sub detect {
93 my ($self, $calc, $i) = @_;
94 my $prices = $calc->prices;
95 my $cndl_name = $self->{'cndl'}->get_name(0);
96 my $bearish_harami_name = $self->get_name(0);
97  
98 return if ($calc->signals->is_available($self->get_name(0), $i));
99 return if (! $self->check_dependencies($calc, $i));
100
101 my $previous_cndl_code = $calc->indicators->get($cndl_name, $i - 1);
102 my $cndl_code = $calc->indicators->get($cndl_name, $i);
103  
104 # Previous CandleCode from 112 to 127
105 # CandleCode from 67 to 47
106 if (($previous_cndl_code >= 112) and ($previous_cndl_code <= 127) and
107 ($cndl_code >= 67) and ($cndl_code <= 47) and
108 ($prices->at($i)->[$OPEN] < $prices->at($i - 1)->[$CLOSE]) and
109 ($prices->at($i)->[$CLOSE] > $prices->at($i - 1)->[$OPEN])
110 )
111 {
112 $calc->signals->set($bearish_harami_name, $i, 1);
113 } else {
114 $calc->signals->set($bearish_harami_name, $i, 0);
115 }
116 }
117  
118 1;