| 1 | package Finance::GeniusTrader::TradeFilters::AroonTrend; | ||
| 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 | use Finance::GeniusTrader::Indicators::AROON; | ||
| 14 | |||
| 15 | @NAMES = ("AroonTrend"); | ||
| 16 | @ISA = qw(Finance::GeniusTrader::TradeFilters); | ||
| 17 | @DEFAULT_ARGS = (); | ||
| 18 | |||
| 19 | =head1 NAME | ||
| 20 | |||
| 21 | Finance::GeniusTrader::TradeFilters::AroonTrend - Allow only trades following the trend defined by Aroon | ||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | This filter tries to limit the risks by refusing trades againts the | ||
| 26 | market (ie like buying in a bear market or selling in a bullish market). | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | sub initialize { | ||
| 31 | my ($self) = @_; | ||
| 32 | |||
| 33 | $self->{'aroon'} = Finance::GeniusTrader::Indicators::AROON->new; | ||
| 34 | return; | ||
| 35 | } | ||
| 36 | |||
| 37 | sub accept_trade { | ||
| 38 | my ($self, $order, $i, $calc, $portfolio) = @_; | ||
| 39 | my $name = $self->{'aroon'}->get_name(2); | ||
| 40 | |||
| 41 | $self->{'aroon'}->calculate($calc, $i); | ||
| 42 | |||
| 43 | if (! $calc->indicators->is_available($name, $i)) | ||
| 44 | { | ||
| 45 | # Refuse if we can't evaluate the risk | ||
| 46 | return 0; | ||
| 47 | } | ||
| 48 | |||
| 49 | if (abs($calc->indicators->get($name, $i)) > 30) | ||
| 50 | { | ||
| 51 | return 0; | ||
| 52 | } else { | ||
| 53 | # Authorize when there's no clear trend | ||
| 54 | return 1; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | 1; |