GeniusTrader/Indicators/Keltner.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 71 CC 4 SCAR 21.5
CC
4
Cov
0%
calculate
20.0
initialize
2.0
BEGIN
2.0
CRAP 8.5
1 package Finance::GeniusTrader::Indicators::Keltner;
2  
3 # Copyright 2002 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 @DEFAULT_ARGS);
11  
12 use Finance::GeniusTrader::ArgsTree;
13 use Finance::GeniusTrader::Indicators;
14 use Finance::GeniusTrader::Indicators::SMA;
15 use Finance::GeniusTrader::Indicators::ATR;
16  
17 @ISA = qw(Finance::GeniusTrader::Indicators);
18 @NAMES = ("Keltner[#*]", "KeltnerUp[#*]", "KeltnerDown[#*]");
19 @DEFAULT_ARGS = (9, 2, "{I:Prices HIGH}", "{I:Prices LOW}", "{I:Prices CLOSE}");
20  
21 =head1 NAME
22  
23 Finance::GeniusTrader::Indicators::Keltner - Keltner Channel
24  
25 =head1 DESCRIPTION
26  
27  
28 =head2 Parameters
29  
30 =over
31  
32 =item Period 1 (default 9)
33  
34 Period on which the indicator has to be calculated
35  
36 =item Constant (default 2)
37  
38 A constant factor with wich the Average True range is multiplied.
39  
40 =back
41  
42 =head2 Creation
43  
44  
45 =head2 Link
46  
47  
48 =cut
49  
50  
51 sub initialize {
52 my ($self) = @_;
53  
54 $self->{'sma'} = Finance::GeniusTrader::Indicators::SMA->new( [ $self->{'args'}->get_arg_names(1),
55 $self->{'args'}->get_arg_names(5) ] );
56 $self->{'atr'} = Finance::GeniusTrader::Indicators::ATR->new( [ $self->{'args'}->get_arg_names(1),
57 $self->{'args'}->get_arg_names(3),
58 $self->{'args'}->get_arg_names(4),
59 $self->{'args'}->get_arg_names(5) ] );
60 }
61  
62 sub calculate {
63 my ($self, $calc, $i) = @_;
64 my $indic = $calc->indicators;
65 my $name = $self->get_name(0);
66 my $lowname = $self->get_name(2);
67 my $upname = $self->get_name(1);
68 my $nb1 = $self->{'args'}->get_arg_values($calc, $i, 1);
69  
70 return if ( !defined($nb1) );
71  
72 # Calculate the depencies
73 $self->remove_volatile_dependencies();
74 $self->add_volatile_indicator_dependency( $self->{'sma'}, $nb1 );
75 $self->add_volatile_indicator_dependency( $self->{'atr'}, $nb1 );
76  
77 return if ( $calc->indicators->is_available($name, $i) &&
78 $calc->indicators->is_available($upname, $i) &&
79 $calc->indicators->is_available($lowname, $i) );
80 return if (! $self->check_dependencies($calc, $i));
81  
82 my $mid = $indic->get($self->{'sma'}->get_name, $i);
83 my $up = $mid + $indic->get($self->{'atr'}->get_name, $i) * $self->{'args'}->get_arg_values($calc, $i, 2);
84 my $low = $mid - $indic->get($self->{'atr'}->get_name, $i) * $self->{'args'}->get_arg_values($calc, $i, 2);
85  
86 $indic->set($name, $i, $mid);
87 $indic->set($upname, $i, $up);
88 $indic->set($lowname, $i, $low);
89 }
90  
91 1;