| 1 | package Finance::GeniusTrader::Systems::ADX; | ||
| 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::Prices; | ||
| 13 | use Finance::GeniusTrader::Systems; | ||
| 14 | use Finance::GeniusTrader::Indicators::ADX; | ||
| 15 | |||
| 16 | @ISA = qw(Finance::GeniusTrader::Systems); | ||
| 17 | @NAMES = ("ADX[#1]"); | ||
| 18 | @DEFAULT_ARGS = (14); | ||
| 19 | |||
| 20 | =pod | ||
| 21 | |||
| 22 | =head1 Trend following system | ||
| 23 | |||
| 24 | =cut | ||
| 25 | |||
| 26 | sub initialize { | ||
| 27 | my ($self) = @_; | ||
| 28 | |||
| 29 | $self->{'allow_multiple'} = 0; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub precalculate_interval { | ||
| 33 | my ($self, $calc, $first, $last) = @_; | ||
| 34 | if ($self->{'args'}->is_constant()) { | ||
| 35 | my $period = $self->{'args'}->get_arg_constant(1); | ||
| 36 | my $adx = Finance::GeniusTrader::Indicators::ADX->new([$period]); | ||
| 37 | $adx->calculate($calc, $last); | ||
| 38 | } | ||
| 39 | return; | ||
| 40 | } | ||
| 41 | |||
| 42 | sub long_signal { | ||
| 43 | my ($self, $calc, $i) = @_; | ||
| 44 | |||
| 45 | my $period = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 46 | my $adx = Finance::GeniusTrader::Indicators::ADX->new([$period]); | ||
| 47 | my $adxname = $adx->get_name; | ||
| 48 | |||
| 49 | $self->remove_volatile_dependencies(); | ||
| 50 | $self->add_volatile_indicator_dependency($adx, 2); | ||
| 51 | |||
| 52 | return 0 if (!$self->check_dependencies($calc, $i)); | ||
| 53 | |||
| 54 | if (($calc->indicators->get($adxname, $i) < 15) | ||
| 55 | && | ||
| 56 | ($calc->indicators->get($adxname, $i - 1) < | ||
| 57 | $calc->indicators->get($adxname, $i)) | ||
| 58 | ) | ||
| 59 | { | ||
| 60 | return 1; | ||
| 61 | } | ||
| 62 | return 0; | ||
| 63 | } | ||
| 64 | |||
| 65 | sub short_signal { | ||
| 66 | my ($self, $calc, $i) = @_; | ||
| 67 | |||
| 68 | return 0; | ||
| 69 | } |