GeniusTrader/Indicators/WTCL.pm untested

filter: Statementstmt 0.0% 0 / 28 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 / 40 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::WTCL;
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::Indicators;
13 use Finance::GeniusTrader::Prices;
14  
15 @ISA = qw(Finance::GeniusTrader::Indicators);
16 @NAMES = ("WTCL[#1]");
17 @DEFAULT_ARGS=(2, "{I:Prices HIGH}", "{I:Prices LOW}", "{I:Prices CLOSE}");
18  
19 =head1 Finance::GeniusTrader::Indicators::WTCL
20  
21 =head2 Overview
22  
23 The Weighted Close indicator is simply an average of each day's price. It gets its name from the fact that extra weight is given to the closing price. The Median Price and Typical Price are similar indicators.
24  
25 =head2 Calculation
26  
27 The Weighted Close indicator is calculated by multiplying the close by $weight, adding the high and the low to this product, and dividing by (2 + $weight). The result is the average price with extra weight given to the closing price.
28  
29 =head2 Parameters
30  
31 The standard Weighted Close is configured with : $weight = 2.
32  
33 =head2 Links
34  
35 http://www.equis.com/free/taaz/weightedclose.html
36 http://www.futuresource.com/industry/wtcl.asp
37  
38 =cut
39  
40 sub initialize {
41 my ($self) = @_;
42 $self->add_arg_dependency(2, 1);
43 $self->add_arg_dependency(3, 1);
44 $self->add_arg_dependency(4, 1);
45 }
46  
47 =head2 Finance::GeniusTrader::Indicators::WTCL::calculate($calc, $day)
48  
49 =cut
50 sub calculate {
51 my ($self, $calc, $i) = @_;
52 my $weight = $self->{'args'}->get_arg_values($calc, $i, 1);
53 my $name = $self->get_name;
54 my $prices = $calc->prices;
55  
56 return if ($calc->indicators->is_available($name, $i));
57 return if (! $self->check_dependencies($calc, $i));
58  
59 # Weighted Close = (Today's High + Today's Low + Today's Close * 2 ) / 4
60 my $wtcl = (( $self->{'args'}->get_arg_values($calc, $i, 2) +
61 $self->{'args'}->get_arg_values($calc, $i, 3) +
62 $self->{'args'}->get_arg_values($calc, $i, 4) * $weight) / (2 + $weight));
63  
64 $calc->indicators->set($name, $i, $wtcl);
65 }
66  
67 1;