App/Chart/Series/Derived/WilliamsAccDist.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 94 CC 3 SCAR 13.3
CC
3
Cov
0%
proc
12.0
longname
2.0
shortname
2.0
CRAP 3.8
1 # Copyright 2006, 2007, 2009, 2010 Kevin Ryde
2  
3 # This file is part of Chart.
4 #
5 # Chart is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3, or (at your option) any later version.
8 #
9 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Chart. If not, see <http://www.gnu.org/licenses/>.
16  
17 package App::Chart::Series::Derived::WilliamsAccDist;
18 use 5.010;
19 use strict;
20 use warnings;
21 use Carp;
22 use List::Util qw(min max);
23 use Locale::TextDomain ('App-Chart');
24  
25 use base 'App::Chart::Series::Indicator';
26 use App::Chart::Series::Derived::OBV;
27 use App::Chart::Series::Derived::SwingIndex;
28  
29  
30 sub longname { __('Williams Accumulation/Distribution') }
31 sub shortname { __('Williams Acc/Dist') }
32 sub manual { __p('manual-node','Williams Accumulation/Distribution') }
33  
34 use constant
35 { type => 'indicator',
36 units => 'WilliamsAccDist',
37 parameter_info => [ ],
38 };
39  
40 sub new {
41 my ($class, $parent) = @_;
42  
43 return $class->SUPER::new
44 (parent => $parent,
45 parameters => [ ],
46 arrays => { values => [] },
47 array_aliases => { });
48 }
49 *fill_part = \&App::Chart::Series::Derived::OBV::fill_part;
50  
51 sub proc {
52 my ($self) = @_;
53 my $parent = $self->parent;
54  
55 my $p = $parent->values_array;
56 my $po = $parent->array('opens') || [];
57 my $ph = $parent->array('highs') || [];
58 my $pl = $parent->array('lows') || [];
59  
60 sub {
61 my ($i, $value, $i_prev, $value_prev) = @_;
62  
63 if ($value > $value_prev) {
64 my $low = $pl->[$i] // $value;
65 return $value - min ($low, $value_prev); # "true low"
66  
67 } elsif ($value < $value_prev) {
68 my $high = $ph->[$i] // $value;
69 return $value - max ($high, $value_prev); # "true high"
70  
71 } else {
72 return 0;
73 }
74 };
75 }
76  
77  
78 1;
79 __END__