GeniusTrader/Indicators/Generic/SumIf.pm untested

filter: Statementstmt 0.0% 0 / 27 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 / 39 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::Generic::SumIf;
2  
3 # Copyright 2003 Oliver Bossert
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);
11  
12 use Finance::GeniusTrader::Indicators;
13 use Finance::GeniusTrader::Prices;
14  
15 @ISA = qw(Finance::GeniusTrader::Indicators);
16 @NAMES = ("SumIf[#*]");
17  
18 =head1 NAME
19  
20 Finance::GeniusTrader::Indicators::Generic::SumIf - Return a sum depending on a signal
21  
22 =head1 DESCRIPTION
23  
24 This indicator takes three parameters. First a signal followed by a
25 period and an indicator. It returns the sum of the days where the Signal
26 is true.
27  
28 =over
29  
30 =item {S:Generic:CrossOverUp {I:RSI} 80} 14 {I:SAR}
31  
32 =back
33  
34  
35 =cut
36  
37 sub initialize {
38 my ($self) = @_;
39  
40 }
41  
42 sub calculate {
43 my ($self, $calc, $i) = @_;
44 my $name = $self->get_name;
45 my $nb = $self->{'args'}->get_arg_values($calc, $i, 2);
46 my $sum = 0;
47  
48 return if ($calc->indicators->is_available($name, $i));
49  
50 for(my $n = $i - $nb + 1; $n <= $i; $n++)
51 {
52 if ($self->{'args'}->get_arg_values($calc, $n, 1)) {
53 $sum += $self->{'args'}->get_arg_values($calc, $n, 3);
54 }
55 }
56  
57 $calc->indicators->set($name, $i, $sum);
58 }