GeniusTrader/CloseStrategy/Stop/ExtremePrices.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 85 CC 5 SCAR 13.6
CC
5
Cov
0%
get_indicative_long_stop
6.0
get_indicative_short_stop
6.0
manage_long_position
6.0
CRAP 3.9
1 package Finance::GeniusTrader::CloseStrategy::Stop::ExtremePrices;
2  
3 # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber
4 # Modified 2004 by Oliver Bossert
5 # This file is distributed under the terms of the General Public License
6 # version 2 or (at your option) any later version.
7  
8 # Standards-Version: 1.0
9  
10 use strict;
11 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
12  
13 use Finance::GeniusTrader::CloseStrategy;
14 use Finance::GeniusTrader::Prices;
15 use Finance::GeniusTrader::Indicators::MIN;
16 use Finance::GeniusTrader::Indicators::MAX;
17  
18 @ISA = qw(Finance::GeniusTrader::CloseStrategy);
19 @NAMES = ("ExtremePrices[#1,#2,#3]");
20 @DEFAULT_ARGS = (20, 1, "{I:Prices CLOSE}");
21  
22 =head1 Finance::GeniusTrader::CloseStrategy::Stop::ExtremePrices
23  
24 This strategy closes the position once the prices have crossed up the
25 highest high in a short position and crossed down the highest low in a
26 logn position.
27  
28 =cut
29  
30 sub initialize {
31 my ($self) = @_;
32  
33 $self->{'min'} = Finance::GeniusTrader::Indicators::MIN->new([ $self->{'args'}->get_arg_names(1) ]);
34 $self->{'max'} = Finance::GeniusTrader::Indicators::MAX->new([ $self->{'args'}->get_arg_names(1) ]);
35  
36 $self->add_indicator_dependency($self->{'min'}, 1);
37 $self->add_indicator_dependency($self->{'max'}, 1);
38 $self->add_prices_dependency(1);
39 }
40  
41 sub get_indicative_long_stop {
42 my ($self, $calc, $i, $order, $pf_manager, $sys_manager) = @_;
43  
44 return if (! $self->check_dependencies($calc, $i));
45  
46 my $percentage = $self->{'args'}->get_arg_values($calc, $i, 2);
47 my $lowest_low = $calc->indicators->get($self->{'min'}->get_name, $i);
48  
49 return ($lowest_low * (1 - $percentage / 100));
50 }
51  
52 sub get_indicative_short_stop {
53 my ($self, $calc, $i, $order, $pf_manager, $sys_manager) = @_;
54  
55 return if (! $self->check_dependencies($calc, $i));
56  
57 my $percentage = $self->{'args'}->get_arg_values($calc, $i, 2);
58 my $highest_high = $calc->indicators->get($self->{'max'}->get_name, $i);
59  
60 return ($highest_high * (1 + $percentage / 100));
61 }
62  
63 sub long_position_opened {
64 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
65  
66 return;
67 }
68  
69 sub short_position_opened {
70 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
71  
72 return;
73 }
74  
75 sub manage_long_position {
76 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
77  
78 return if (! $self->check_dependencies($calc, $i));
79  
80 my $percentage = $self->{'args'}->get_arg_values($calc, $i, 2);
81 my $lowest_low = $calc->indicators->get($self->{'min'}->get_name, $i);
82 $position->set_stop($lowest_low * (1 - $percentage / 100));
83  
84 return;
85 }
86  
87 sub manage_short_position {
88 my ($self, $calc, $i, $position, $ps_manager, $sys_manager) = @_;
89  
90 return if (! $self->check_dependencies($calc, $i));
91  
92 my $percentage = $self->{'args'}->get_arg_values($calc, $i, 2);
93 my $highest_high = $calc->indicators->get($self->{'max'}->get_name, $i);
94 $position->set_stop($highest_high * (1 + $percentage / 100));
95  
96 return;
97 }
98