GeniusTrader/OrderFactory/ClosedToClose.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 37 CC 2 SCAR 11.0
CC
2
Cov
0%
initialize
6.0
create_buy_order
2.0
create_sell_order
2.0
CRAP 3.0
1 package Finance::GeniusTrader::OrderFactory::ClosedToClose;
2  
3 # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber
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::OrderFactory;
13 use Finance::GeniusTrader::Prices;
14  
15 @ISA = qw(Finance::GeniusTrader::OrderFactory);
16 @NAMES = ("ClosedToClose[#1]");
17 @DEFAULT_ARGS = (0);
18  
19 =head1 NAME
20  
21 Finance::GeniusTrader::OrderFactory::StopOnExtreme
22  
23 =head1 DESCRIPTION
24  
25 Create an order that will be x% above or below current close prices.
26  
27 =cut
28  
29 sub initialize {
30 my ($self) = @_;
31 $self->add_arg_dependency(1, 1) unless $self->{'args'}->is_constant(1);
32 }
33  
34 sub create_buy_order {
35 my ($self, $calc, $i, $sys_manager, $pf_manager) = @_;
36
37 $self->{'long_factor'} = 1 + $self->{'args'}->get_arg_values($calc, $i, 1) / 100;
38
39 my $price = $calc->prices->at($i)->[$CLOSE] * $self->{'long_factor'};
40 return $pf_manager->buy_limited_price($calc, $sys_manager->get_name, $price);
41 }
42  
43 sub create_sell_order {
44 my ($self, $calc, $i, $sys_manager, $pf_manager) = @_;
45  
46 $self->{'short_factor'} = 1 - $self->{'args'}->get_arg_values($calc, $i, 1) / 100;
47
48 my $price = $calc->prices->at($i)->[$CLOSE] * $self->{'short_factor'};
49 return $pf_manager->sell_conditional($calc, $sys_manager->get_name, $price);
50 }
51  
52 1;