| 1 | package Finance::GeniusTrader::Indicators::PFEraw; | ||
| 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 | # ras hack based on version dated 24 Apr 2005 2099 bytes | ||
| 10 | # $Id$ | ||
| 11 | |||
| 12 | use strict; | ||
| 13 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 14 | |||
| 15 | use Finance::GeniusTrader::ArgsTree; | ||
| 16 | use Finance::GeniusTrader::Indicators; | ||
| 17 | |||
| 18 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 19 | @NAMES = ("PFEraw[#*]"); | ||
| 20 | @DEFAULT_ARGS = (10,2,1,"{I:Prices CLOSE}"); | ||
| 21 | |||
| 22 | =head1 NAME | ||
| 23 | |||
| 24 | Finance::GeniusTrader::Indicators::PFE - Polarized Fractal Efficiency | ||
| 25 | |||
| 26 | =head1 DESCRIPTION | ||
| 27 | |||
| 28 | |||
| 29 | =head2 Parameters | ||
| 30 | |||
| 31 | =over | ||
| 32 | |||
| 33 | =item Period (default 10) | ||
| 34 | |||
| 35 | The first argument is the period used to calculate the average. | ||
| 36 | |||
| 37 | =item Exponent (default 2) | ||
| 38 | |||
| 39 | =item Correction-Factor (default 1) | ||
| 40 | |||
| 41 | Set this factor to 200 for values > 1000 | ||
| 42 | |||
| 43 | =item Datasource | ||
| 44 | |||
| 45 | =back | ||
| 46 | |||
| 47 | =head2 Creation | ||
| 48 | |||
| 49 | |||
| 50 | =head2 Link | ||
| 51 | |||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | sub initialize { | ||
| 56 | my ($self) = @_; | ||
| 57 | } | ||
| 58 | |||
| 59 | sub calculate { | ||
| 60 | my ($self, $calc, $i) = @_; | ||
| 61 | my $indic = $calc->indicators; | ||
| 62 | my $name = $self->get_name(0); | ||
| 63 | my $length = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 64 | my $exp = $self->{'args'}->get_arg_values($calc, $i, 2); | ||
| 65 | my $factor = $self->{'args'}->get_arg_values($calc, $i, 3); | ||
| 66 | |||
| 67 | $self->remove_volatile_dependencies(); | ||
| 68 | $self->add_volatile_arg_dependency(4, $length); | ||
| 69 | return if ($calc->indicators->is_available($name, $i)); | ||
| 70 | return if (! $self->check_dependencies($calc, $i)); | ||
| 71 | |||
| 72 | my $pfe = $self->{'args'}->get_arg_values($calc, $i, 4) | ||
| 73 | - $self->{'args'}->get_arg_values($calc, $i-$length, 4); | ||
| 74 | $pfe = sqrt( ($pfe/$factor)**$exp + $length**$exp ); | ||
| 75 | |||
| 76 | my $c2c = 0; | ||
| 77 | for (my $counter=$i-$length+1; $counter<=$i; $counter++) { | ||
| 78 | my $diff = $self->{'args'}->get_arg_values($calc, $counter, 4) | ||
| 79 | - $self->{'args'}->get_arg_values($calc, $counter-1, 4); | ||
| 80 | $c2c += sqrt ( ($diff/$factor)**$exp + 1 ); | ||
| 81 | } | ||
| 82 | |||
| 83 | my $arg = $self->{'args'}->get_arg_values($calc, $i, 4) | ||
| 84 | - $self->{'args'}->get_arg_values($calc, $i-$length, 4); | ||
| 85 | if ( $arg > 0 ) { | ||
| 86 | $pfe = ( $pfe/$c2c*100 ); | ||
| 87 | } else { | ||
| 88 | $pfe = ( -$pfe/$c2c*100 ); | ||
| 89 | } | ||
| 90 | |||
| 91 | $indic->set($name, $i, $pfe); | ||
| 92 | } | ||
| 93 | |||
| 94 | 1; |