| 1 | package Finance::GeniusTrader::Indicators::Interquartil; | ||
| 2 | |||
| 3 | # Copyright 2003 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 | |||
| 14 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 15 | @NAMES = ("IQ[#*]"); | ||
| 16 | @DEFAULT_ARGS = (80, 50, "{I:Prices CLOSE}"); | ||
| 17 | |||
| 18 | =head1 NAME | ||
| 19 | |||
| 20 | Finance::GeniusTrader::Indicators::Interquartil - Interquartil-Distance | ||
| 21 | |||
| 22 | =head1 DESCRIPTION | ||
| 23 | |||
| 24 | The Interquartil-distance; which is the position at which you can | ||
| 25 | divide the data by x% on the left side and (100-x)% on the right side. | ||
| 26 | |||
| 27 | =head2 Parameters | ||
| 28 | |||
| 29 | =over | ||
| 30 | |||
| 31 | =item Percentage | ||
| 32 | |||
| 33 | Percentage of the IQD (median = 50%) | ||
| 34 | |||
| 35 | =item Period (default 50) | ||
| 36 | |||
| 37 | The first argument is the period used to calculed the average. | ||
| 38 | |||
| 39 | =item Other data input | ||
| 40 | |||
| 41 | The Data for the calculation. | ||
| 42 | |||
| 43 | =back | ||
| 44 | |||
| 45 | =head2 Creation | ||
| 46 | |||
| 47 | To create a kind of dynamic borders for the RSI try: | ||
| 48 | |||
| 49 | Indicators::Interquartil(90,50,{I:RSI}) | ||
| 50 | Indicators::Interquartil(10,50,{I:RSI}) | ||
| 51 | |||
| 52 | |||
| 53 | =cut | ||
| 54 | sub initialize { | ||
| 55 | my ($self) = @_; | ||
| 56 | } | ||
| 57 | |||
| 58 | sub calculate { | ||
| 59 | my ($self, $calc, $i) = @_; | ||
| 60 | my $nb = $self->{'args'}->get_arg_values($calc, $i, 2); | ||
| 61 | my $name = $self->get_name; | ||
| 62 | |||
| 63 | return if (! defined($nb)); | ||
| 64 | |||
| 65 | $self->remove_volatile_dependencies(); | ||
| 66 | $self->add_volatile_prices_dependency($nb); | ||
| 67 | |||
| 68 | return if (! $self->check_dependencies($calc, $i)); | ||
| 69 | |||
| 70 | my @values = (); | ||
| 71 | for(my $n = $i - $nb + 1; $n <= $i; $n++) | ||
| 72 | { | ||
| 73 | my $val = $self->{'args'}->get_arg_values($calc, $n, 3); | ||
| 74 | return if (! defined($val)); | ||
| 75 | push @values, $val; | ||
| 76 | } | ||
| 77 | @values = sort { $a <=> $b } @values; | ||
| 78 | my $pos = int( $self->{'args'}->get_arg_values($calc, $i, 1) * ($#values) / 100 ); | ||
| 79 | $pos = 0 if ($pos < 0); | ||
| 80 | $pos = $#values if ($pos > $#values); | ||
| 81 | my $erg = $values[$pos]; | ||
| 82 | |||
| 83 | $calc->indicators()->set($name, $i, $erg); | ||
| 84 | } | ||
| 85 | |||
| 86 | 1; |