GeniusTrader/TradeFilters/AroonTrend.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 38 CC 3 SCAR 17.5
CC
3
Cov
0%
accept_trade
12.0
initialize
2.0
BEGIN
2.0
CRAP 5.8
1 package Finance::GeniusTrader::TradeFilters::AroonTrend;
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(@NAMES @ISA @DEFAULT_ARGS);
11  
12 use Finance::GeniusTrader::TradeFilters;
13 use Finance::GeniusTrader::Indicators::AROON;
14  
15 @NAMES = ("AroonTrend");
16 @ISA = qw(Finance::GeniusTrader::TradeFilters);
17 @DEFAULT_ARGS = ();
18  
19 =head1 NAME
20  
21 Finance::GeniusTrader::TradeFilters::AroonTrend - Allow only trades following the trend defined by Aroon
22  
23 =head1 DESCRIPTION
24  
25 This filter tries to limit the risks by refusing trades againts the
26 market (ie like buying in a bear market or selling in a bullish market).
27  
28 =cut
29  
30 sub initialize {
31 my ($self) = @_;
32
33 $self->{'aroon'} = Finance::GeniusTrader::Indicators::AROON->new;
34 return;
35 }
36  
37 sub accept_trade {
38 my ($self, $order, $i, $calc, $portfolio) = @_;
39 my $name = $self->{'aroon'}->get_name(2);
40
41 $self->{'aroon'}->calculate($calc, $i);
42  
43 if (! $calc->indicators->is_available($name, $i))
44 {
45 # Refuse if we can't evaluate the risk
46 return 0;
47 }
48  
49 if (abs($calc->indicators->get($name, $i)) > 30)
50 {
51 return 0;
52 } else {
53 # Authorize when there's no clear trend
54 return 1;
55 }
56 }
57  
58 1;