| 1 | package Finance::GeniusTrader::Systems::ADX2; | ||
| 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 | use Finance::GeniusTrader::Indicators::ADXR; | ||
| 16 | |||
| 17 | @ISA = qw(Finance::GeniusTrader::Systems); | ||
| 18 | @NAMES = ("ADX2[#1]"); | ||
| 19 | @DEFAULT_ARGS = (14); | ||
| 20 | |||
| 21 | =pod | ||
| 22 | |||
| 23 | =head1 Trend following system 2 | ||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | sub initialize { | ||
| 28 | my ($self) = @_; | ||
| 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_interval($calc, $first, $last); | ||
| 38 | my $adxr = Finance::GeniusTrader::Indicators::ADXR->new([$period]); | ||
| 39 | $adxr->calculate_interval($calc, $first, $last); | ||
| 40 | } | ||
| 41 | return; | ||
| 42 | } | ||
| 43 | |||
| 44 | sub long_signal { | ||
| 45 | my ($self, $calc, $i) = @_; | ||
| 46 | |||
| 47 | my $period = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 48 | my $adx = Finance::GeniusTrader::Indicators::ADX->new([$period]); | ||
| 49 | my $adx_name = $adx->get_name(0); | ||
| 50 | my $positive_di_name = $adx->get_name(1); | ||
| 51 | my $negative_di_name = $adx->get_name(2); | ||
| 52 | my $adxr = Finance::GeniusTrader::Indicators::ADXR->new([$period]); | ||
| 53 | my $adxr_name = $adxr->get_name; | ||
| 54 | |||
| 55 | $self->remove_volatile_dependencies(); | ||
| 56 | $self->add_volatile_indicator_dependency($adx, 2); | ||
| 57 | $self->add_volatile_indicator_dependency($adxr, 1); | ||
| 58 | |||
| 59 | return 0 if (!$self->check_dependencies_interval($calc, $i - 1, $i)); | ||
| 60 | |||
| 61 | if (($calc->indicators->get($positive_di_name, $i) > | ||
| 62 | $calc->indicators->get($negative_di_name, $i)) | ||
| 63 | && | ||
| 64 | ($calc->indicators->get($adx_name, $i - 1) < | ||
| 65 | $calc->indicators->get($adx_name, $i)) | ||
| 66 | && | ||
| 67 | ($calc->indicators->get($adxr_name, $i) > 25) | ||
| 68 | ) | ||
| 69 | { | ||
| 70 | return 1; | ||
| 71 | } | ||
| 72 | return 0; | ||
| 73 | } | ||
| 74 | |||
| 75 | sub short_signal { | ||
| 76 | my ($self, $calc, $i) = @_; | ||
| 77 | |||
| 78 | my $period = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 79 | my $adx = Finance::GeniusTrader::Indicators::ADX->new([$period]); | ||
| 80 | my $adx_name = $adx->get_name(0); | ||
| 81 | my $positive_di_name = $adx->get_name(1); | ||
| 82 | my $negative_di_name = $adx->get_name(2); | ||
| 83 | my $adxr = Finance::GeniusTrader::Indicators::ADXR->new([$period]); | ||
| 84 | my $adxr_name = $adxr->get_name; | ||
| 85 | |||
| 86 | $self->remove_volatile_dependencies(); | ||
| 87 | $self->add_volatile_indicator_dependency($adx, 2); | ||
| 88 | $self->add_volatile_indicator_dependency($adxr, 1); | ||
| 89 | |||
| 90 | return 0 if (!$self->check_dependencies_interval($calc, $i - 1, $i)); | ||
| 91 | |||
| 92 | if (($calc->indicators->get($positive_di_name, $i) < | ||
| 93 | $calc->indicators->get($negative_di_name, $i)) | ||
| 94 | && | ||
| 95 | ($calc->indicators->get($adx_name, $i - 1) < | ||
| 96 | $calc->indicators->get($adx_name, $i)) | ||
| 97 | && | ||
| 98 | ($calc->indicators->get($adxr_name, $i) > 25) | ||
| 99 | ) | ||
| 100 | { | ||
| 101 | return 1; | ||
| 102 | } | ||
| 103 | return 0; | ||
| 104 | } |