GeniusTrader/Indicators/RAVI.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 51 CC 4 SCAR 22.2
CC
4
Cov
0%
calculate
20.0
initialize
2.0
BEGIN
2.0
CRAP 9.2
1 package Finance::GeniusTrader::Indicators::RAVI;
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  
16 @ISA = qw(Finance::GeniusTrader::Indicators);
17 @NAMES = ("RAVI[#*]");
18 @DEFAULT_ARGS = (7, 65, "{I:Prices CLOSE}");
19  
20 =head1 NAME
21  
22 Finance::GeniusTrader::Indicators::RAVI - RAVI Trendindicator
23  
24 =head1 DESCRIPTION
25  
26 The RAVI is a simple yet efficient trendindicator. It is calculated as
27 follows:
28  
29 RAVI = ABS ( 100 * ( SMA(Short) - SMA(Long) ) / SMA(Long) )
30  
31 The long Period divided by the short should always be 10.
32 A Trend is indicated if the RAVI crosses the 3%-level.
33  
34  
35 =head2 Parameters
36  
37 =over
38  
39 =item Short Period (default 7)
40  
41 The first argument is the period used to calculed the short average.
42  
43 =item Long Period (default 65)
44  
45 The second argument is the period used to calculed the long average.
46  
47 =back
48  
49 =cut
50  
51  
52 sub initialize {
53 my ($self) = @_;
54  
55 $self->{'sma1'} = Finance::GeniusTrader::Indicators::SMA->new( [ $self->{'args'}->get_arg_names(1),
56 $self->{'args'}->get_arg_names(3) ] );
57 $self->{'sma2'} = Finance::GeniusTrader::Indicators::SMA->new( [ $self->{'args'}->get_arg_names(2),
58 $self->{'args'}->get_arg_names(3) ] );
59  
60 $self->add_indicator_dependency($self->{'sma1'}, 1);
61 $self->add_indicator_dependency($self->{'sma2'}, 1);
62 }
63  
64 sub calculate {
65 my ($self, $calc, $i) = @_;
66 my $indic = $calc->indicators;
67 my $name = $self->get_name;
68  
69 return if ($calc->indicators->is_available($name, $i));
70 return if (! $self->check_dependencies($calc, $i));
71  
72 my $sma1 = $indic->get($self->{'sma1'}->get_name, $i);
73 my $sma2 = $indic->get($self->{'sma2'}->get_name, $i);
74  
75 my $ravi = ($sma2 == 0) ? 0 : abs( 100 * ($sma1 - $sma2) / $sma2 );
76  
77 $indic->set($name, $i, $ravi);
78 }
79  
80 1;