GeniusTrader/Indicators/Generic/Cum.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 35 CC 3 SCAR 18.4
CC
3
Cov
0%
calculate
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 6.3
1 package Finance::GeniusTrader::Indicators::Generic::Cum;
2  
3 # Copyright 2008 Thomas Weigert
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: Cum.pm,v 1.3 2008/03/13 05:29:59 ras Exp ras $
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::Indicators::BPCorrelation;
17 use Finance::GeniusTrader::Prices;
18  
19 @ISA = qw(Finance::GeniusTrader::Indicators);
20 @NAMES = ("Cum[#1]");
21 @DEFAULT_ARGS = ("{I:Prices CLOSE}");
22  
23 =pod
24  
25 =head1 Finance::GeniusTrader::Indicators::Generic::Cum
26  
27 =head2 Overview
28  
29 This function keeps a running total of its input. Each period is calculated,
30 it adds the current value of the input to the previous total. For example,
31 {I:Generic:Cum 1}
32 will keep adding 1 for each period of time loaded. In effect, this counts
33 how many records are currently loaded.
34  
35 =cut
36  
37 =pod
38  
39 =head2 Finance::GeniusTrader::Indicators::Generic::Cum::calculate($calc, $day)
40  
41 =cut
42  
43 sub calculate {
44 my ($self, $calc, $i) = @_;
45 my $indic = $calc->indicators;
46 my $prices = $calc->prices;
47 my $name = $self->get_name;
48  
49 return if ($indic->is_available($name, $i));
50  
51 my $value;
52  
53 if ($indic->is_available($name, $i - 1)) {
54 $value = $indic->get($name, $i - 1) + $self->{'args'}->get_arg_values($calc, $i, 1);
55 } else {
56 $value = $self->{'args'}->get_arg_values($calc, $i, 1);
57 }
58
59 $indic->set($name, $i, $value);
60 }
61  
62 1;