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

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 74 CC 2 SCAR 9.3
CC
2
Cov
0%
roc1_proc
6.0
longname
2.0
manual
2.0
CRAP 2.5
1 # Copyright 2008, 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::REMA_Momentum;
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::Derived::REMA;
27  
28 sub longname { __('REMA Momentum') }
29 *shortname = \&longname;
30 sub manual { __p('manual-node','REMA Momentum') }
31  
32 use constant
33 { hlines => [ 0 ],
34 type => 'indicator',
35 units => 'roc_fraction',
36 parameter_info => App::Chart::Series::Derived::REMA::parameter_info(),
37 };
38  
39 *new = \&App::Chart::Series::Derived::REMA::new;
40  
41 sub warmup_count {
42 my ($class_or_self, $N, $lambda) = @_;
43 return 1 + App::Chart::Series::Derived::REMA->warmup_count ($N, $lambda);
44 }
45  
46 sub proc {
47 my ($class, $N, $lambda) = @_;
48 my $rema_proc = App::Chart::Series::Derived::REMA->proc ($N, $lambda);
49 my $roc1_proc = roc1_proc ();
50 return sub {
51 my ($value) = @_;
52 return $roc1_proc->($rema_proc->($value));
53 };
54 }
55 sub roc1_proc {
56 my $prev;
57 return sub {
58 my ($value) = @_;
59 my $ret;
60 if (defined $prev && $prev != 0) {
61 $ret = ($value - $prev) / $prev;
62 }
63 $prev = $value;
64 return $ret;
65 };
66 }
67  
68 1;
69 __END__