GeniusTrader/CloseStrategy/Stop/Breakeven.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 58 CC 3 SCAR 11.7
CC
3
Cov
0%
manage_long_position
6.0
manage_short_position
6.0
initialize
2.0
CRAP 3.2
1 package Finance::GeniusTrader::CloseStrategy::Stop::Breakeven;
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  
16 @ISA = qw(Finance::GeniusTrader::CloseStrategy);
17 @NAMES = ("Breakeven[#1,#2]");
18 @DEFAULT_ARGS = (5, 2);
19  
20 =head1 Finance::GeniusTrader::CloseStrategy::Stop::Breakeven
21  
22 =head2 Overview
23  
24 This strategy place a stop order when we reach a profit target, to be sure
25 that if things are going wrong we will never let a winning trade become a
26 losing one ! The stop should be calculated by including commission &
27 slippage.
28  
29 =cut
30  
31 sub initialize {
32 my ($self) = @_;
33 }
34  
35 sub get_indicative_long_stop {
36 my ($self, $calc, $i, $order, $pf_manager, $sys_manager) = @_;
37  
38 return 0;
39 }
40  
41 sub get_indicative_short_stop {
42 my ($self, $calc, $i, $order, $pf_manager, $sys_manager) = @_;
43
44 return 0;
45 }
46  
47 sub long_position_opened {
48 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
49  
50 return;
51 }
52  
53 sub short_position_opened {
54 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
55  
56 return;
57 }
58  
59 sub manage_long_position {
60 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
61  
62 $self->{'long_profit_factor'} = 1 + $self->{'args'}->get_arg_values($calc, $i, 1) / 100;
63 $self->{'long_stop_factor'} = 1 + $self->{'args'}->get_arg_values($calc, $i, 2) / 100;
64 if ($calc->prices->at($i)->[$LAST] >= ($position->open_price * $self->{'long_profit_factor'})) {
65 $position->set_stop($position->open_price * $self->{'long_stop_factor'});
66 }
67 return;
68 }
69  
70 sub manage_short_position {
71 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
72  
73 $self->{'short_profit_factor'} = 1 - $self->{'args'}->get_arg_values($calc, $i, 1) / 100;
74 $self->{'short_stop_factor'} = 1 - $self->{'args'}->get_arg_values($calc, $i, 2) / 100;
75 if ($calc->prices->at($i)->[$LAST] <= ($position->open_price * $self->{'short_profit_factor'})) {
76 $position->set_stop($position->open_price * $self->{'short_stop_factor'});
77 }
78 return;
79 }
80  
81 1;