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

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 102 CC 2 SCAR 8.8
CC
2
Cov
0%
proc
6.0
longname
2.0
shortname
2.0
CRAP 2.4
1 # Copyright 2006, 2007, 2009, 2010, 2011 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::MASS;
18 use 5.010;
19 use strict;
20 use warnings;
21 use Carp;
22 use Locale::TextDomain 1.17; # for __p()
23 use Locale::TextDomain ('App-Chart');
24  
25 use base 'App::Chart::Series::Indicator';
26 use App::Chart::Series::Calculation;
27 use App::Chart::Series::Derived::EMA;
28 use App::Chart::Series::Derived::EMAx2;
29 use App::Chart::Series::Derived::WilliamsR;
30  
31  
32 # "The Mass Index", Donald Dorsey, TASC June 1992
33 #
34 # http://www.incrediblecharts.com/technical/mass_index.php
35 #
36 # http://www.wallstreettape.com/tutorials/ta/c21.asp
37 # Chartfilter description.
38 #
39  
40 sub longname { __('MASS Index') }
41 sub shortname { __('MASS') }
42 sub manual { __p('manual-node','MASS Index') }
43  
44 use constant
45 { type => 'indicator',
46 units => 'MASS',
47 parameter_info => [ { name => __('EMA days'),
48 key => 'mass_ema_days',
49 type => 'integer',
50 minimum => 1,
51 default => 9 },
52 { name => __('Sum days'),
53 key => 'mass_sum_days',
54 type => 'integer',
55 minimum => 1,
56 default => 25 }],
57 };
58  
59 sub new {
60 my ($class, $parent, $ema_N, $sum_N) = @_;
61 ### MASS new(): @_
62  
63 $ema_N //= parameter_info()->[0]->{'default'};
64 ($ema_N > 0) || croak "MASS bad ema_N: $ema_N";
65  
66 $sum_N //= parameter_info()->[1]->{'default'};
67 ($sum_N > 0) || croak "MASS bad sum_N: $sum_N";
68  
69 return $class->SUPER::new
70 (parent => $parent,
71 parameters => [ $ema_N, $sum_N ],
72 arrays => { values => [] },
73 array_aliases => { });
74 }
75 sub proc {
76 my ($class_or_self, $ema_N, $sum_N) = @_;
77 my $ema_proc = App::Chart::Series::Derived::EMA->proc($ema_N);
78 my $ema2_proc = App::Chart::Series::Derived::EMA->proc($ema_N);
79 my $sum_proc = App::Chart::Series::Calculation->sum($sum_N);
80  
81 return sub {
82 my ($high, $low, $close) = @_;
83 my $e = $ema_proc->($high - $low);
84 my $e2 = $ema2_proc->($e);
85 return $sum_proc->($e2 == 0 ? 0 : $e / $e2);
86 };
87 }
88 *fill_part = \&App::Chart::Series::Derived::WilliamsR::fill_part;
89  
90 sub warmup_count {
91 my ($class_or_self, $ema_N, $sum_N) = @_;
92 return $sum_N - 1
93 + App::Chart::Series::Derived::EMAx2->warmup_count ($ema_N);
94 }
95  
96 1;
97 __END__