GeniusTrader/Indicators/PGO.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 61 CC 3 SCAR 15.5
CC
3
Cov
0%
calculate
12.0
initialize
2.0
BEGIN
2.0
CRAP 4.7
1 package Finance::GeniusTrader::Indicators::PGO;
2  
3 # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber
4 # This file is distributed under the terms of the General Public License
5 # version 2 or (at your option) any later version.
6  
7 # Standards-Version: 1.0
8  
9 use strict;
10 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
11  
12 use Finance::GeniusTrader::Prices;
13 use Finance::GeniusTrader::Indicators;
14 use Finance::GeniusTrader::Indicators::SMA;
15 use Finance::GeniusTrader::Indicators::EMA;
16 use Finance::GeniusTrader::Indicators::TR;
17  
18 @ISA = qw(Finance::GeniusTrader::Indicators);
19 @NAMES = ("PGO[#*]");
20 @DEFAULT_ARGS = (89, "{I:Prices HIGH}", "{I:Prices LOW}", "{I:Prices CLOSE}");
21  
22 =head1 Finance::GeniusTrader::Indicators::PGO
23  
24 =head2 Overview
25  
26 The Pretty Good Oscillator (PGO) ...
27  
28 =head2 Calculation
29  
30 PGO = (Close - N-Day SMA of Close) / N-Day EMA of True Range)
31  
32 =head2 Parameters
33  
34 N = 89
35  
36 =cut
37  
38 sub initialize {
39 my $self = shift;
40  
41 my $tr = "{I:TR " . $self->{'args'}->get_arg_names(2) . " " .
42 $self->{'args'}->get_arg_names(3) . " " .
43 $self->{'args'}->get_arg_names(4) . "}";
44 $self->{'ema'} = Finance::GeniusTrader::Indicators::EMA->new([$self->{'args'}->get_arg_names(1),
45 $tr ]);
46 $self->{'sma'} = Finance::GeniusTrader::Indicators::SMA->new([ $self->{'args'}->get_arg_names(1),
47 $self->{'args'}->get_arg_names(4) ]);
48  
49 $self->add_indicator_dependency($self->{'ema'}, 1);
50 $self->add_indicator_dependency($self->{'sma'}, 1);
51 $self->add_arg_dependency(4,1);
52 }
53  
54 sub calculate {
55 my ($self, $calc, $i) = @_;
56 my $indic = $calc->indicators;
57 my $prices = $calc->prices;
58 my $name = $self->get_name;
59 my $sma_name = $self->{'sma'}->get_name;
60 my $ema_name = $self->{'ema'}->get_name;
61  
62 return if ($indic->is_available($name, $i));
63 return if (! $self->check_dependencies($calc, $i));
64
65 # Calculate PGO
66 my $pgo = (($self->{'args'}->get_arg_values($calc, $i, 4) -
67 $indic->get($sma_name, $i)) / $indic->get($ema_name, $i));
68
69 # Return the result
70 $indic->set($name, $i, $pgo);
71 }
72  
73 1;