GeniusTrader/CloseStrategy/Generic.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 62 CC 5 SCAR 18.4
CC
5
Cov
0%
manage_long_position
12.0
manage_short_position
12.0
initialize
2.0
CRAP 6.3
1 package Finance::GeniusTrader::CloseStrategy::Generic;
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::Prices;
14 use Finance::GeniusTrader::CloseStrategy;
15 use Finance::GeniusTrader::Eval;
16 use Finance::GeniusTrader::Tools qw(:generic);
17  
18 @ISA = qw(Finance::GeniusTrader::CloseStrategy);
19 @NAMES = ("Generic[#*]");
20 @DEFAULT_ARGS = ("{S:Generic:False}", "{S:Generic:False}");
21  
22 =head1 NAME
23  
24 CloseStrategy::Generic
25  
26 =head1 DESCRIPTION
27  
28 This is a simple Generic Closestrategy that closes the trade based on
29 one or two signals.
30  
31 =head2 Parameters
32  
33 =over
34  
35 =item First Signal
36  
37 The first Signal is the signal used to close a long position.
38  
39 =item Second Signal
40  
41 The second signal is used to close short positions.
42  
43 =back
44  
45 =cut
46  
47 sub initialize {
48 my ($self) = @_;
49 }
50  
51 sub precalculate_interval {
52 my ($self, $calc, $first, $last) = @_;
53 }
54  
55 sub manage_long_position {
56 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
57  
58 return 0 if (! $self->check_dependencies($calc, $i));
59
60 if ( $self->{'args'}->get_arg_values($calc, $i, 1) == 1 )
61 {
62 my $order = $pf_manager->sell_market_price($calc,
63 $sys_manager->get_name);
64 $pf_manager->submit_order_in_position($position, $order, $i, $calc);
65 }
66
67 return;
68 }
69  
70 sub manage_short_position {
71 my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_;
72
73 return if (! $self->check_dependencies($calc, $i));
74  
75 if ( $self->{'args'}->get_nb_args() >= 2 &&
76 $self->{'args'}->get_arg_values($calc, $i, 2) == 1 )
77 {
78 my $order = $pf_manager->buy_market_price($calc,
79 $sys_manager->get_name);
80 $pf_manager->submit_order_in_position($position, $order, $i, $calc);
81 }
82
83 return;
84 }
85  
86 1;