GeniusTrader/Indicators/ATR.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 45 CC 3 SCAR 16.7
CC
3
Cov
0%
calculate
12.0
initialize
2.0
BEGIN
2.0
CRAP 5.3
1 package Finance::GeniusTrader::Indicators::ATR;
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 use Finance::GeniusTrader::Indicators::SMA;
14 use Finance::GeniusTrader::Indicators::TR;
15  
16 @ISA = qw(Finance::GeniusTrader::Indicators);
17 @NAMES = ("ATR[#*]");
18 @DEFAULT_ARGS = (14, "{I:Prices HIGH}", "{I:Prices LOW}", "{I:Prices CLOSE}");
19  
20 =head1 Finance::GeniusTrader::Indicators::ATR
21  
22 =head2 Overview
23  
24 The Average True Index (ATR) is a measure of volatility. High ATR values often occur at market bottom following a 'panic' sell-off.
25 Low ATR values are often found during extended sideways periods, such as those found at tops and after consolidation periods.
26  
27 =head2 Calculation
28  
29 The Average True Index is a moving average of the True Ranges.
30  
31 =head2 Parameters
32  
33 The standard ATR works with a fourteen-day parameter : n = 14
34  
35 =head2 Example
36  
37 Finance::GeniusTrader::Indicators::ATR->new()
38 Finance::GeniusTrader::Indicators::ATR->new([12])
39  
40 =head2 Note
41  
42 The Average True Range can be interpreted using the same techniques that are used with other volatility indicators.
43  
44 =head2 Validation
45  
46 This indicators is validated by the values from comdirect.de.
47 The stock used was the DAX (data from yahoo) at the 04.06.2003:
48  
49 ATR[14] [2003-06-04] = 79.2343 (comdirect=79.23)
50  
51 =head2 Links
52  
53 http://www.equis.com/free/taaz/avertrurang.html
54 http://stockcharts.com/education/What/IndicatorAnalysis/indic_ATR.html
55 http://www.finance-net.com/apprendre/techniques/atr.phtml
56  
57 =cut
58  
59 sub initialize {
60 my $self = shift;
61  
62 my $tr = "{I:TR " . $self->{'args'}->get_arg_names(2) . " " .
63 $self->{'args'}->get_arg_names(3) . " " .
64 $self->{'args'}->get_arg_names(4) . "}";
65 $self->{'sma'} = Finance::GeniusTrader::Indicators::SMA->new([$self->{'args'}->get_arg_names(1), $tr ]);
66 $self->add_indicator_dependency($self->{'sma'}, 1);
67 }
68  
69 =head2 Finance::GeniusTrader::Indicators::ATR::calculate($calc, $day)
70  
71 =cut
72 sub calculate {
73 my ($self, $calc, $i) = @_;
74 my $indic = $calc->indicators;
75 my $sma_name = $self->{'sma'}->get_name;
76 my $atr_name = $self->get_name(0);
77  
78 return if ($indic->is_available($atr_name, $i));
79 return if (! $self->check_dependencies($calc, $i));
80
81 # Get the Average True Range
82 my $atr_value = $indic->get($sma_name, $i);
83
84 # Return the result
85 $indic->set($atr_name, $i, $atr_value);
86  
87 }
88  
89 1;