App/Chart/Series/Derived/MASS.pm

filter: Statementstmt 100% 20 / 20 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 100% 27 / 27 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« App/Chart/Series/Derived/LaguerreFilter.pm ↑ Summary App/Chart/Series/Indicator.pm »
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 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Locale::TextDomain 1.17; # for __p()
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Locale::TextDomain ('App-Chart');
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use base 'App::Chart::Series::Indicator';
Subroutine BEGIN: called CC=1 SCAR=0.0
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__
98  
99 # =head1 NAME
100 #
101 # App::Chart::Series::Derived::MASS -- Dorsey's MASS index
102 #
103 # =head1 SYNOPSIS
104 #
105 # my $series = $parent->MASS($N);
106 #
107 # =head1 DESCRIPTION
108 #
109 # ...
110 #
111 # =head1 SEE ALSO
112 #
113 # L<App::Chart::Series>, L<App::Chart::Series::Derived::EMA>
114 #
115 # =cut
« App/Chart/Series/Derived/LaguerreFilter.pm ↑ Summary App/Chart/Series/Indicator.pm »