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

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 91 CC 2 SCAR 8.8
CC
2
Cov
0%
new
6.0
longname
2.0
shortname
2.0
CRAP 2.4
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::TypicalPrice;
18 use 5.010;
19 use strict;
20 use warnings;
21 use Carp;
22 use List::Util qw(min max);
23 use Scalar::Util;
24 use Locale::TextDomain ('App-Chart');
25  
26 use App::Chart::Database;
27 use App::Chart::TZ;
28 use base 'App::Chart::Series::Indicator';
29  
30 sub longname { __('Typical Price (H+L+C)/3') }
31 sub shortname { __('Typ') }
32 sub manual { __p('manual-node','Typical Price') }
33  
34 use constant
35 { type => 'selector',
36 };
37  
38 sub new {
39 my ($class, $parent) = @_;
40 if (! $parent->array('highs') && ! $parent->array('lows')) {
41 return $parent;
42 }
43 return $class->SUPER::new
44 (parent => $parent,
45 arrays => { values => [] },
46 array_aliases => { });
47 }
48  
49 *fill_part = \&App::Chart::Series::Derived::WilliamsR::fill_part;
50 use constant warmup_count => 0;
51  
52 sub proc {
53 my ($class_or_self) = @_;
54 return \&typical_price;
55 }
56 sub typical_price {
57 my ($high, $low, $close) = @_;
58 return (($high//$close) + ($low//$close) + $close) / 3;
59 }
60  
61 # sub fill_part {
62 # my ($self, $lo, $hi) = @_;
63 # my $parent = $self->{'parent'};
64 #
65 # $parent->fill ($lo, $hi);
66 # my $closes = $parent->values_array;
67 # my $highs = $parent->array('highs') || $closes;
68 # my $lows = $parent->array('lows') || $closes;
69 # my $s = $self->values_array;
70 #
71 # $hi = min ($hi, $#$closes);
72 # if ($#$s < $hi) { $#$s = $hi; } # pre-extend
73 #
74 # foreach my $i ($lo .. $hi) {
75 # my $close = $closes->[$i] // next;
76 #
77 # # mean (H+L+C)/3
78 # $s->[$i] = (($lows->[$i] // $close)
79 # + ($highs->[$i] // $close)
80 # + $close) / 3;
81 # }
82 # }
83  
84 1;
85 __END__