GeniusTrader/Indicators/SWMA.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 45 CC 3 SCAR 18.4
CC
3
Cov
0%
calculate
12.0
initialize
2.0
BEGIN
2.0
CRAP 6.3
1 package Finance::GeniusTrader::Indicators::SWMA;
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 use strict;
8 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
9  
10 use Finance::GeniusTrader::Indicators;
11  
12 @ISA = qw(Finance::GeniusTrader::Indicators);
13 @NAMES = ("SWMA[#1,#2]");
14 @DEFAULT_ARGS = (5, "{I:Prices CLOSE}");
15  
16 =head1 Finance::GeniusTrader::Indicators::SWMA
17  
18 The Sine-Weighted Moving Average (SWMA) is a moving average using a sine factor to take into account both time and price movements. Very good at catching tops and bottoms, while filtering out unnecessary noise.
19  
20 =head2 Calculation
21  
22 SWMA = ( Sum of (sin(n*180/6*PI/180) * Close(i)) for i = 1 to i = period ) / (Sum
23 of (sin(n*180/6*PI/180)) for i = 1 to i = period)
24  
25 =head2 Examples
26  
27 Finance::GeniusTrader::Indicators::SWMA->>new()
28 Finance::GeniusTrader::Indicators::SWMA->new([30, {I:Prices OPEN}])
29  
30 =head2 Links
31  
32 http://www.ivorix.com/en/products/tech/smooth/swma.html
33  
34 =cut
35  
36 sub initialize {
37 my ($self) = @_;
38  
39 $self->add_prices_dependency($self->{'args'}->get_arg_constant(1));
40 }
41  
42 =head2 Finance::GeniusTrader::Indicators::SWMA::calculate($calc, $day)
43  
44 =cut
45 sub calculate {
46 my ($self, $calc, $i) = @_;
47 my $nb = $self->{'args'}->get_arg_constant(1);
48 my $name = $self->get_name;
49 my $counter = 0;
50 my $numerator = 0;
51 my $denominator = 0;
52
53 return if ($calc->indicators->is_available($name, $i));
54 return if (! $self->check_dependencies($calc, $i));
55  
56 my $pi = 3.141512;
57 for(my $n = $i - $nb + 1; $n <= $i; $n++)
58 {
59 $numerator += (sin(($nb - $counter) * 180 / 6 * $pi / 180) * $self->{'args'}->get_arg_values($calc, $n, 2));
60 $denominator += (sin(($nb - $counter) * 180 / 6 * $pi / 180));
61 $counter += 1;
62 }
63 my $swma = $numerator / $denominator;
64 $calc->indicators->set($name, $i, $swma);
65 }
66