| 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; |