GeniusTrader/Indicators/WWMA.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 38 CC 3 SCAR 19.5
CC
3
Cov
0%
calculate
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 7.0
1 package Finance::GeniusTrader::Indicators::WWMA;
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  
14 @ISA = qw(Finance::GeniusTrader::Indicators);
15 @NAMES = ("WWMA[#1]");
16 @DEFAULT_ARGS = (20, "{I:Prices CLOSE}");
17  
18 =head1 Finance::GeniusTrader::Indicators::WWMA
19  
20 Welles Wilder Moving Average (WWMA) is a modified verson of the EMA.
21  
22 =head2 Calculation
23  
24 WWMA(i) = (1/n) * Close(i) + (1 - 1/n) * WWMA(i-1)
25  
26 =head2 Examples
27  
28 Finance::GeniusTrader::Indicators::WWMA->new()
29 Finance::GeniusTrader::Indicators::WWMA->new([15])
30 Finance::GeniusTrader::Indicators::WWMA->new([30], "OPEN", $GET_OPEN)
31  
32  
33 =head1 NOTICES
34  
35 this version of Welles Wilder Moving Average (WWMA) is depreciated
36 in favor of Wilders (Finance::GeniusTrader::Indicators::Wilders).
37  
38  
39 =cut
40  
41 #sub initialize {
42 # my ($self) = @_;
43 #}
44  
45 =head2 Finance::GeniusTrader::Indicators::WWMA::calculate($calc, $day)
46  
47 =cut
48 sub calculate {
49 my ($self, $calc, $i) = @_;
50 my $nb = $self->{'args'}->get_arg_values($calc, $i, 1);
51 my $name = $self->get_name;
52 my $wwma = 0;
53
54 $self->remove_volatile_dependencies();
55 $self->add_volatile_arg_dependency(2, $nb);
56  
57 return if ($calc->indicators->is_available($name, $i));
58 return if (! $self->check_dependencies($calc, $i));
59  
60 $wwma = $self->{'args'}->get_arg_values($calc, $i - $nb + 1, 2);
61 for(my $n = $i - $nb + 2; $n <= $i; $n++)
62 {
63 $wwma *= (1 - (1 / $nb));
64 $wwma += ((1 / $nb) * $self->{'args'}->get_arg_values($calc, $n, 2));
65 }
66 $calc->indicators->set($name, $i, $wwma);
67 }
68  
69 1;