GeniusTrader/Signals/Volatility/NR.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 55 CC 4 SCAR 21.5
CC
4
Cov
0%
detect
20.0
initialize
2.0
BEGIN
2.0
CRAP 8.5
1 package Finance::GeniusTrader::Signals::Volatility::NR;
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::Signals;
13 use Finance::GeniusTrader::Prices;
14 use Finance::GeniusTrader::Indicators::Range;
15 use Finance::GeniusTrader::Indicators::Generic::MinInPeriod;
16  
17 @ISA = qw(Finance::GeniusTrader::Signals);
18 @NAMES = ("NR[#1]");
19 @DEFAULT_ARGS = (7);
20  
21 =head1 NAME
22  
23 Finance::GeniusTrader::Signals::Volatility::NR
24  
25 =head1 DESCRIPTION
26  
27 NR is for Narrowest Range. It is parametered with the period length to
28 look at for the size of ranges.
29  
30 =cut
31 sub initialize {
32 my ($self) = @_;
33
34 $self->{'range'} = Finance::GeniusTrader::Indicators::Range->new;
35 $self->{'min_range'} = Finance::GeniusTrader::Indicators::Generic::MinInPeriod->new(
36 [ $self->{'args'}->get_arg_constant(1), "{I:Range}" ]);
37  
38 $self->add_indicator_dependency($self->{'range'}, $self->{'args'}->get_arg_constant(1));
39 $self->add_indicator_dependency($self->{'min_range'}, 1);
40 $self->add_prices_dependency(1);
41 }
42  
43 sub detect {
44 my ($self, $calc, $i) = @_;
45 my $indic = $calc->indicators;
46 my $min_name = $self->{'min_range'}->get_name;
47 my $range_name = $self->{'range'}->get_name;
48 my $name = $self->get_name;
49  
50 return if ($calc->signals->is_available($name, $i));
51 return if (! $self->check_dependencies($calc, $i));
52
53 # If the narrowest range is the range of today
54 if ( $indic->get($min_name, $i) == $indic->get($range_name, $i) )
55 {
56 $calc->signals->set($name, $i, 1);
57 } else {
58 $calc->signals->set($name, $i, 0);
59 }
60 }
61  
62 1;