GeniusTrader/Indicators/BBO.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 57 CC 4 SCAR 20.8
CC
4
Cov
0%
calculate
20.0
initialize
2.0
BEGIN
2.0
CRAP 8.0
1 package Finance::GeniusTrader::Indicators::BBO;
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::Indicators;
13 use Finance::GeniusTrader::Prices;
14 use Finance::GeniusTrader::Tools qw(:math);
15 use Finance::GeniusTrader::ArgsTree;
16 use Finance::GeniusTrader::Indicators::BOL;
17  
18 @ISA = qw(Finance::GeniusTrader::Indicators);
19 @NAMES = ("BBO[#*]");
20 @DEFAULT_ARGS = (20,2,"{I:Prices CLOSE}");
21  
22 =head1 NAME
23  
24 Finance::GeniusTrader::Indicators::BBO - %B - the Bollinger Band Oscillator
25  
26 =head1 DESCRIPTION
27  
28 Bollinger Calculated this oscillator. The %B falls below 0 if the
29 Price crosses the lower Band. It is set to > 1 if the price raises
30 above the upper band.
31  
32 =head2 Parameters
33  
34 The parameters are identical with those of the BOL-Indicator.
35  
36 =cut
37  
38  
39 sub initialize {
40 my $self = shift;
41 $self->{'bol'} = Finance::GeniusTrader::Indicators::BOL->new( [ $self->{'args'}->get_arg_names() ]);
42 $self->add_indicator_dependency($self->{'bol'}, 1);
43 }
44  
45 sub calculate {
46 my ($self, $calc, $i) = @_;
47 my $indic = $calc->indicators;
48 my $bolup = $self->{'bol'}->get_name(1);
49 my $bollow = $self->{'bol'}->get_name(2);
50  
51 my $val = $self->{'args'}->get_arg_values($calc, $i, 3);
52 my $name = $self->get_name();
53  
54 return if ($calc->indicators->is_available($name, $i));
55 return if (! $self->check_dependencies($calc, $i) );
56  
57 my $pos = 0;
58 $pos = ( $val - $indic->get($bollow,$i) ) /
59 ( $indic->get($bolup, $i) - $indic->get($bollow, $i) )
60 unless ($indic->get($bolup, $i) - $indic->get($bollow, $i) == 0);
61  
62 $indic->set($name, $i, $pos);
63 }
64  
65 1;