GeniusTrader/Indicators/MEAN.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 38 CC 3 SCAR 17.5
CC
3
Cov
0%
calculate
12.0
initialize
2.0
BEGIN
2.0
CRAP 5.8
1 package Finance::GeniusTrader::Indicators::MEAN;
2  
3 # Copyright 2008 Karsten Wippler
4 # Based on and for GeniusTrader (C) 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber
5 # This file is distributed under the terms of the General Public License
6 # version 2 or (at your option) any later version.
7  
8 # $Id: MEAN.pm,v 1.1 2008/03/14 16:53:45 ras Exp $
9  
10 # Standards-Version: 1.0
11  
12 use strict;
13 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
14  
15 use Finance::GeniusTrader::Indicators;
16 use Finance::GeniusTrader::Prices;
17  
18 @ISA = qw(Finance::GeniusTrader::Indicators);
19 @NAMES = ("MEAN[#1,#2]");
20 @DEFAULT_ARGS=("{I:Prices HIGH}", "{I:Prices LOW}");
21  
22 =head1 Finance::GeniusTrader::Indicators::MEAN
23  
24 =head2 Overview
25  
26 The mean indicator is simply an average of each days high and low.
27  
28 =head2 Calculation
29  
30 mean =(high+low)/2
31  
32 =head2 Links
33  
34 =cut
35  
36 sub initialize {
37 my ($self) = @_;
38 $self->add_arg_dependency(1, 1);
39 $self->add_arg_dependency(2, 1);
40 }
41  
42 sub calculate {
43 my ($self, $calc, $i) = @_;
44 my $name = $self->get_name;
45 my $prices = $calc->prices;
46  
47 return if ($calc->indicators->is_available($name, $i));
48 return if (! $self->check_dependencies($calc, $i));
49  
50 my $mean = (( $self->{'args'}->get_arg_values($calc, $i, 1) +
51 $self->{'args'}->get_arg_values($calc, $i, 2) )
52 /2 );
53  
54 $calc->indicators->set($name, $i, $mean);
55 }
56  
57 1;