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

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 96 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::PGO;
18 use 5.010;
19 use strict;
20 use warnings;
21 use Carp;
22 use List::Util qw(min max);
23 use Locale::TextDomain 1.17; # for __p()
24 use Locale::TextDomain ('App-Chart');
25  
26 use base 'App::Chart::Series::Indicator';
27 use App::Chart::Series::Derived::SMA;
28 use App::Chart::Series::Derived::EMA;
29 use App::Chart::Series::Derived::ATR;
30 use App::Chart::Series::Derived::WilliamsR;
31  
32  
33 # http://www.purebytes.com/archives/omega/1999/msg12885.html
34 #
35 # http://www.mjohnson.com/trecipes/pgoy2k.zip [gone]
36 #
37 # http://trader.online.pl/MSZ/e-w-Pretty_Good_Oscillator.html
38 # Sample CSCO
39 #
40 # http://xeatrade.com/trading/2/P/1139.html
41 # Metastock formula copied from http://www.traderclub.com, showing EMA[89]
42 #
43 #
44 # http://www.elitetrader.com/vb/printthread.php?threadid=18598
45 # Bit of discussion from Nov 2003.
46 #
47  
48 sub longname { __('PGO - Pretty Good Oscillator') }
49 sub shortname { __('PGO') }
50 sub manual { __p('manual-node','Pretty Good Oscillator') }
51  
52 use constant
53 { hlines => [ -3, 0, 3, ],
54 type => 'indicator',
55 units => 'pgo',
56 parameter_info => [ { name => __('Days'),
57 key => 'pgo_days',
58 type => 'integer',
59 minimum => 1,
60 default => 89 } ],
61 };
62  
63 sub new {
64 my ($class, $parent, $N) = @_;
65  
66 $N //= parameter_info()->[0]->{'default'};
67 ($N > 0) || croak "PGO bad N: $N";
68  
69 return $class->SUPER::new
70 (parent => $parent,
71 parameters => [ $N ],
72 arrays => { values => [] },
73 array_aliases => { });
74 }
75 sub proc {
76 my ($class_or_self, $N) = @_;
77 my $sma_proc = App::Chart::Series::Derived::SMA->proc($N);
78 my $atr_proc = App::Chart::Series::Derived::ATR->proc
79 (App::Chart::Series::Derived::EMA::N_to_Wilder_N($N));
80  
81 return sub {
82 my ($high, $low, $close) = @_;
83 my $avg = $sma_proc->($close);
84 my $den = $atr_proc->($high, $low, $close);
85 return ($den != 0 ? ($close - $avg) / $den : undef);
86 };
87 }
88 sub warmup_count {
89 my ($class_or_self, $N) = @_;
90 return max (App::Chart::Series::Derived::SMA->warmup_count($N),
91 App::Chart::Series::Derived::ATR->warmup_count($N));
92 }
93 *fill_part = \&App::Chart::Series::Derived::WilliamsR::fill_part;
94  
95 1;
96 __END__