GeniusTrader/Systems/TFS.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 96 CC 6 SCAR 18.8
CC
6
Cov
0%
long_signal
12.0
short_signal
12.0
new
6.0
CRAP 6.5
1 package Finance::GeniusTrader::Systems::TFS;
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 use strict;
8 use vars qw(@ISA @NAMES);
9  
10 use Finance::GeniusTrader::Prices;
11 use Finance::GeniusTrader::Systems;
12 use Finance::GeniusTrader::Indicators::TETHER;
13 use Finance::GeniusTrader::Indicators::VOSC;
14  
15 @ISA = qw(Finance::GeniusTrader::Systems);
16 @NAMES = ("TFS[#1,#2]");
17  
18 =head1 Trend Following System (TFS)
19  
20 =cut
21 sub new {
22 my $type = shift;
23 my $class = ref($type) || $type;
24 my $args = shift;
25  
26 my $self = { "args" => defined($args) ? $args : [50, 7] };
27  
28 return manage_object(\@NAMES, $self, $class, $self->{'args'}, "");
29 }
30  
31 sub initialize {
32 my ($self) = @_;
33  
34 $self->{'tether'} = Finance::GeniusTrader::Indicators::TETHER->new([ $self->{'args'}[0] ]);
35 $self->{'vosc'} = Finance::GeniusTrader::Indicators::VOSC->new([ $self->{'args'}[1] ]);
36  
37 $self->add_indicator_dependency($self->{'tether'}, 2);
38 $self->add_indicator_dependency($self->{'vosc'}, 1);
39 $self->add_prices_dependency(2);
40 }
41  
42  
43 sub long_signal {
44 my ($self, $calc, $i) = @_;
45
46 return 0 if (! $self->check_dependencies($calc, $i));
47
48 if ( ( $calc->prices->at($i)->[$CLOSE] >
49 $calc->indicators->get($self->{'tether'}->get_name, $i) )
50 &&
51 ( $calc->prices->at($i - 1)->[$CLOSE] <=
52 $calc->indicators->get($self->{'tether'}->get_name, $i - 1) )
53 &&
54 ( $calc->indicators->get($self->{'vosc'}->get_name, $i) > 0 )
55 )
56 {
57 return 1;
58 }
59 return 0;
60 }
61  
62 sub short_signal {
63 my ($self, $calc, $i) = @_;
64
65 return 0 if (! $self->check_dependencies($calc, $i));
66  
67 if ( ( $calc->prices->at($i)->[$CLOSE] <
68 $calc->indicators->get($self->{'tether'}->get_name, $i) )
69 &&
70 ( $calc->prices->at($i - 1)->[$CLOSE] >=
71 $calc->indicators->get($self->{'tether'}->get_name, $i - 1) )
72 &&
73 ( $calc->indicators->get($self->{'vosc'}->get_name, $i) < 0 )
74 )
75 {
76 return 1;
77 }
78 return 0;
79 }
80  
81 1;