« GeniusTrader/Analyzers/BuyAndHold.pm
↑ Summary
GeniusTrader/Indicators/Cheating/MeanPossiblePerformance.pm »
| 1 | package Finance::GeniusTrader::Indicators::ADXR; | ||
| 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 | # $Id$ | ||
| 10 | |||
| 11 | use strict; | ||
| 12 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 13 | |||
| 14 | use Finance::GeniusTrader::Indicators; | ||
| 15 | use Finance::GeniusTrader::Indicators::ADX; | ||
| 16 | |||
| 17 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 18 | @NAMES = ("ADXR[#*]"); | ||
| 19 | @DEFAULT_ARGS = (14, 14, "{I:Prices HIGH}", "{I:Prices LOW}", "{I:Prices CLOSE}"); | ||
| 20 | |||
| 21 | =pod | ||
| 22 | |||
| 23 | =head1 Finance::GeniusTrader::Indicators::ADXR | ||
| 24 | |||
| 25 | =head2 Overview | ||
| 26 | |||
| 27 | =head2 Calculation | ||
| 28 | |||
| 29 | ADXR = (Today's ADX + ADX #1 days ago) / 2 | ||
| 30 | |||
| 31 | =head2 Examples | ||
| 32 | |||
| 33 | Finance::GeniusTrader::Indicators::ADXR->new() | ||
| 34 | Finance::GeniusTrader::Indicators::ADXR->new([20]) | ||
| 35 | |||
| 36 | =head2 Links | ||
| 37 | |||
| 38 | =cut | ||
| 39 | |||
| 40 | sub initialize { | ||
| 41 | my $self = shift; | ||
| 42 | |||
| 43 | # Initilize ADX | ||
| 44 | $self->{'adx'} = Finance::GeniusTrader::Indicators::ADX->new([ $self->{'args'}->get_arg_names(2), | ||
| 45 | $self->{'args'}->get_arg_names(3), | ||
| 46 | $self->{'args'}->get_arg_names(4), | ||
| 47 | $self->{'args'}->get_arg_names(5) ] ); | ||
| 48 | } | ||
| 49 | |||
| 50 | =head2 Finance::GeniusTrader::Indicators::ADXR::calculate($calc, $day) | ||
| 51 | |||
| 52 | =cut | ||
| 53 | sub calculate { | ||
| 54 | my ($self, $calc, $i) = @_; | ||
| 55 | my $indic = $calc->indicators; | ||
| 56 | my $period = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 57 | my $adx_name = $self->{'adx'}->get_name; | ||
| 58 | my $adxr_name = $self->get_name(0); | ||
| 59 | my $adxr_value = 0; | ||
| 60 | |||
| 61 | return if ($indic->is_available($adxr_name, $i)); | ||
| 62 | |||
| 63 | $self->remove_volatile_dependencies(); | ||
| 64 | $self->add_volatile_indicator_dependency($self->{'adx'}, $period); | ||
| 65 | |||
| 66 | return if (! $self->check_dependencies($calc, $i)); | ||
| 67 | return if (! $self->check_dependencies($calc, $i - $period)); | ||
| 68 | |||
| 69 | # Calculate ADXR value | ||
| 70 | $adxr_value = ($indic->get($adx_name, $i) + $indic->get($adx_name, $i - $period)) / 2; | ||
| 71 | |||
| 72 | # Return ADX[#1] value | ||
| 73 | $indic->set($adxr_name, $i, $adxr_value); | ||
| 74 | |||
| 75 | } | ||
| 76 | |||
| 77 | sub calculate_interval { | ||
| 78 | my ($self, $calc, $first, $last) = @_; | ||
| 79 | |||
| 80 | # Calculate ADXR in the "reverse" way | ||
| 81 | for (my $i = $last; $i >= $first; $i--) | ||
| 82 | { | ||
| 83 | $self->calculate($calc, $i); | ||
| 84 | } | ||
| 85 | |||
| 86 | } | ||
| 87 | |||
| 88 | |||
| 89 | |||
| 90 | 1; |