GeniusTrader/Indicators/MaxPossibleGain.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 58 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::MaxPossibleGain;
2  
3 # Copyright 2000-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  
16 @ISA = qw(Finance::GeniusTrader::Indicators);
17 @NAMES = ("MaxPossibleGain[#*]", "MaxPossibleGainDays[#*]");
18 @DEFAULT_ARGS = (20, "{I:Prices HIGH}");
19  
20  
21 =head1 NAME
22  
23 Finance::GeniusTrader::Indicators::MaxPossibleGain - Shows the maximal Gain for a long-strategy
24  
25 =head1 DESCRIPTION
26  
27 This indicator calculates the maximum gain that is possible in a
28 certain period of time. Be aware that this indicator "knows" the
29 future so don't use it for your trading strategies :)
30  
31 =head1 PARAMETERS
32  
33 =over
34  
35 =item Number of days
36  
37 The number of days the indicator looks in the future
38  
39 =item Data
40  
41 This is the data to use as input. If you don't specify anything, the
42 high price will be used by default.
43  
44 =back
45  
46  
47 =cut
48  
49 sub initialize {
50 }
51  
52 sub calculate {
53 my ($self, $calc, $i) = @_;
54 my $name = $self->get_name(0);
55 my $nameday = $self->get_name(1);
56 my $lastday = $calc->prices->count();
57 my $days = $self->{'args'}->get_arg_values($calc, $i, 1);
58  
59 return if ( $calc->indicators->is_available($name, $i) &&
60 $calc->indicators->is_available($nameday, $i) );
61  
62 return if ($i+$days >= $lastday);
63  
64 my $res = $self->{'args'}->get_arg_values($calc, $i+1, 2) -
65 $self->{'args'}->get_arg_values($calc, $i, 2);
66 my $resday = 1;
67 my $buy = $self->{'args'}->get_arg_values($calc, $i, 2);
68 for (my $j=$i+1; $j<=$i+$days; $j++) {
69 my $today = $self->{'args'}->get_arg_values($calc, $j, 2);
70 if ( $today - $buy > $res ) {
71 $res = $today - $buy;
72 $resday = $j-$i;
73 }
74 }
75  
76 $calc->indicators->set($name, $i, $res);
77 $calc->indicators->set($nameday, $i, $resday);
78  
79 }