| 1 | package Finance::GeniusTrader::Indicators::TDREI; | ||
| 2 | |||
| 3 | # Copyright 2002 Oliver Bossert | ||
| 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::Indicators; | ||
| 13 | use Finance::GeniusTrader::Prices; | ||
| 14 | use Finance::GeniusTrader::Tools qw(:math); | ||
| 15 | use Finance::GeniusTrader::ArgsTree; | ||
| 16 | use Finance::GeniusTrader::Indicators::Generic::Eval; | ||
| 17 | |||
| 18 | |||
| 19 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 20 | @NAMES = ("TDREI[#*]"); | ||
| 21 | @DEFAULT_ARGS = (2, 5, "{I:Prices HIGH}", "{I:Prices LOW}", "{I:Prices CLOSE}"); # Momentum, Period | ||
| 22 | |||
| 23 | =head1 NAME | ||
| 24 | |||
| 25 | Finance::GeniusTrader::Indicators::TDREI - Tom Demarks REI | ||
| 26 | |||
| 27 | =head1 DESCRIPTION | ||
| 28 | |||
| 29 | A new oscillator introduced by Tom DeMark. | ||
| 30 | |||
| 31 | =head2 Parameters | ||
| 32 | |||
| 33 | =over | ||
| 34 | |||
| 35 | =item Momentum (default 2) | ||
| 36 | |||
| 37 | =item Period (default 10) | ||
| 38 | |||
| 39 | =back | ||
| 40 | |||
| 41 | =head2 Creation | ||
| 42 | |||
| 43 | Finance::GeniusTrader::Indicators::TDREI->new() | ||
| 44 | |||
| 45 | =head2 Links | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | |||
| 50 | sub initialize { | ||
| 51 | my $self = shift; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub calculate { | ||
| 55 | my ($self, $calc, $i) = @_; | ||
| 56 | my $indic = $calc->indicators; | ||
| 57 | my $name = $self->get_name; | ||
| 58 | |||
| 59 | $self->remove_volatile_dependencies(); | ||
| 60 | $self->add_volatile_arg_dependency(3, 2 * ( $self->{'args'}->get_arg_values($calc, $i, 1) + | ||
| 61 | $self->{'args'}->get_arg_values($calc, $i, 2) + 1) ); | ||
| 62 | $self->add_volatile_arg_dependency(4, 2 * ($self->{'args'}->get_arg_values($calc, $i, 1) + | ||
| 63 | $self->{'args'}->get_arg_values($calc, $i, 2) + 1) ); | ||
| 64 | $self->add_volatile_arg_dependency(5, 2 * ($self->{'args'}->get_arg_values($calc, $i, 1) + | ||
| 65 | $self->{'args'}->get_arg_values($calc, $i, 2) + 1) ); | ||
| 66 | |||
| 67 | return if ($calc->indicators->is_available($name, $i)); | ||
| 68 | return if (! $self->check_dependencies($calc, $i) ); | ||
| 69 | |||
| 70 | my $sumval = 0; | ||
| 71 | my $sumabs = 0; | ||
| 72 | my $mom = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 73 | my $nb = $self->{'args'}->get_arg_values($calc, $i, 2); | ||
| 74 | |||
| 75 | for (my $n = 0; $n < $nb; $n++) { | ||
| 76 | my $h = $self->{'args'}->get_arg_values($calc, $i-$n, 3); | ||
| 77 | my $l = $self->{'args'}->get_arg_values($calc, $i-$n, 4); | ||
| 78 | my $h2 = $self->{'args'}->get_arg_values($calc, $i-$n-$mom, 3); | ||
| 79 | my $l2 = $self->{'args'}->get_arg_values($calc, $i-$n-$mom, 4); | ||
| 80 | my $h5 = $self->{'args'}->get_arg_values($calc, $i-$n-$nb, 3); | ||
| 81 | my $l5 = $self->{'args'}->get_arg_values($calc, $i-$n-$nb, 4); | ||
| 82 | my $h6 = $self->{'args'}->get_arg_values($calc, $i-$n-$nb-1, 3); | ||
| 83 | my $l6 = $self->{'args'}->get_arg_values($calc, $i-$n-$nb-1, 4); | ||
| 84 | my $c7 = $self->{'args'}->get_arg_values($calc, $i-$n-$nb-$mom, 5); | ||
| 85 | my $c8 = $self->{'args'}->get_arg_values($calc, $i-$n-$nb-$mom-1, 5); | ||
| 86 | |||
| 87 | if ( ( ($h>=$l5 || $h>=$l6) && ($l<=$h5 || $l<=$h6) ) || | ||
| 88 | ( ($h2>=$c7 || $h2>=$c8) && ($l2<=$c7 || $l2<=$c8) ) ) { | ||
| 89 | $sumval += ($h - $h2 + $l - $l2); | ||
| 90 | $sumabs += abs($h-$h2) + abs($l-$l2); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | if ($sumabs == 0) { | ||
| 95 | $sumabs += 0.00001; | ||
| 96 | } | ||
| 97 | |||
| 98 | my $erg = 100 * $sumval / $sumabs; | ||
| 99 | |||
| 100 | $indic->set($name, $i, $erg); | ||
| 101 | |||
| 102 | } | ||
| 103 | |||
| 104 | 1; |