GeniusTrader/TradeFilters/OneTrade.pm untested

filter: Statementstmt 0.0% 0 / 19 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 28 CC 3 SCAR 19.5
CC
3
Cov
0%
accept_trade
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 7.0
1 package Finance::GeniusTrader::TradeFilters::OneTrade;
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(@NAMES @ISA @DEFAULT_ARGS);
11  
12 use Finance::GeniusTrader::TradeFilters;
13  
14 @NAMES = ("SingleTrade");
15 @ISA = qw(Finance::GeniusTrader::TradeFilters);
16 @DEFAULT_ARGS = ();
17  
18 =head1 NAME
19  
20 Finance::GeniusTrader::TradeFilters::OneTrade - Refuse simultaneous trades
21  
22 =head1 DESCRIPTION
23  
24 This filter refuses a new trade if a position is actually open. It will
25 however accept it if it's in the process of being closed.
26  
27 =cut
28  
29 sub accept_trade {
30 my ($self, $order, $i, $calc, $portfolio) = @_;
31
32 my @pos = $portfolio->list_open_positions($order->source);
33 foreach (@pos)
34 {
35 if ($_->code eq $order->code)
36 {
37 if (! $_->being_closed)
38 {
39 return 0;
40 }
41 }
42 }
43 return 1;
44 }
45  
46 1;