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

filter: Statementstmt 0.0% 0 / 60 Branchbran n/a Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 85 CC 1 SCAR 6.9
CC
1
Cov
0%
longname
2.0
shortname
2.0
new
2.0
CRAP 2.0
1 # Copyright 2007, 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::TrendingBandiniLines;
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::SMA;
27  
28 # http://trader.online.pl/MSZ/e-w-Trending_Bandini.html
29 # Formula.
30 #
31  
32 sub longname { __('Trending Bandini Lines') }
33 sub shortname { __('Bandini') }
34 # FIXME: not in the manual yet
35 # sub manual { __p('manual-node','Trending Bandini') }
36  
37 use constant
38 { type => 'average',
39 priority => -10,
40 parameter_info => [],
41 };
42  
43 use constant { LINES_COUNT => 10 };
44  
45  
46 sub new {
47 my ($class, $parent) = @_;
48  
49 my @arrays_array;
50 my %arrays;
51 foreach my $i (1 .. LINES_COUNT) {
52 $arrays{"ma_$i"} = $arrays_array[$i] = [];
53 }
54 return $class->SUPER::new
55 (parent => $parent,
56 parameters => [],
57 arrays_array => \@arrays_array,
58 arrays => \%arrays,
59 array_aliases => { values => 'ma_'.LINES_COUNT });
60 }
61 use constant warmup_count => LINES_COUNT;
62  
63 sub fill_part {
64 my ($self, $lo, $hi) = @_;
65 my $parent = $self->{'parent'};
66  
67 my $warmup_count = $self->warmup_count_for_position ($lo);
68 my $start = $parent->find_before ($lo, $warmup_count);
69 $parent->fill ($start, $hi);
70 my $p = $parent->values_array;
71  
72 $hi = min ($hi, $#$p);
73 my @procs = map {App::Chart::Series::Derived::SMA->proc(2)} (1 .. LINES_COUNT);
74  
75 foreach my $i ($start .. $lo-1) {
76 my $value = $p->[$i] // next;
77 foreach (@procs) {
78 $value = $_->($value);
79 }
80 }
81  
82 my $arrays = $self->{'arrays_array'};
83 foreach my $i ($lo .. $hi) {
84 my $value = $p->[$i] // next;
85  
86 foreach my $j (0 .. $#procs) {
87 $arrays->[$j]->[$i] = $value = $procs[$j]->($value);
88 }
89 }
90 }
91  
92 1;
93 __END__