GeniusTrader/Indicators/Cheating/ForwardKPercent.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 59 CC 5 SCAR 26.1
CC
5
Cov
0%
calculate
30.0
initialize
2.0
BEGIN
2.0
CRAP 13.7
1 package Finance::GeniusTrader::Indicators::Cheating::ForwardKPercent;
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 use Finance::GeniusTrader::Indicators::Generic::MaxInPeriod;
16  
17 @ISA = qw(Finance::GeniusTrader::Indicators);
18 @NAMES = ("ForwardKPercent[#*]");
19 @DEFAULT_ARGS = (3, "{I:Prices CLOSE}", "{I:Prices HIGH}", "{I:Prices LOW}", );
20  
21 =head1 NAME
22  
23 Finance::GeniusTrader::Indicators::ForwardKPercent - Probability to make a profitable trade
24  
25 =head1 DESCRIPTION
26  
27 This indicator calculates the K%-value:
28  
29 CLOSE - MIN(3, Low)
30 K% (3) = ------------------------------
31 MAX(3, HIGH) - MIN(3,Low)
32  
33 Be aware that this indicator "knows" the future so don''t use it for
34 your trading strategies :)
35  
36 =head1 PARAMETERS
37  
38 =over
39  
40 =item Number of days
41  
42 The number of days the indicator looks in the future
43  
44 =back
45  
46  
47 =cut
48  
49 sub initialize {
50 my ($self) = @_;
51 }
52  
53 sub calculate {
54 my ($self, $calc, $i) = @_;
55 my $name = $self->get_name;
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 return if ($i+$days >= $lastday);
61  
62 my $close = $self->{'args'}->get_arg_values($calc, $i, 2);
63 my $high = $self->{'args'}->get_arg_values($calc, $i, 3);
64 my $low = $self->{'args'}->get_arg_values($calc, $i, 4);
65  
66 for (my $j=$i+1; $j<=$i+$days; $j++) {
67 my $t_high = $self->{'args'}->get_arg_values($calc, $j, 3);
68 my $t_low = $self->{'args'}->get_arg_values($calc, $j, 4);
69 $high = $t_high if ( $t_high > $high );
70 $low = $t_low if ( $t_low < $low );
71 }
72  
73 my $res = ( $close - $low ) / ( $high - $low );
74  
75 $calc->indicators->set($name, $i, $res);
76  
77 }