From: GeniusTrader C. r. <ra...@ge...> - 2004-03-02 22:36:52
|
Update of /bourse/cvsroot/GT/Indicators In directory arrakis:/scratch/tmp/cvs-serv22606/Indicators Modified Files: GAPO.pm REMA.pm VHF.pm Log Message: - More func cleaning. Thanks to João Antunes Costa. --- /bourse/cvsroot/GT/Indicators/GAPO.pm 2003/01/21 21:15:25 1.4 +++ /bourse/cvsroot/GT/Indicators/GAPO.pm 2004/03/02 21:36:51 1.5 @@ -5,7 +5,7 @@ # version 2 or (at your option) any later version. use strict; -use vars qw(@ISA @NAMES); +use vars qw(@ISA @NAMES @DEFAULT_ARGS); use GT::Indicators; use GT::Indicators::Generic::MinInPeriod; @@ -13,7 +13,8 @@ use GT::Prices; @ISA = qw(GT::Indicators); -@NAMES = ("GAPO[#1]"); +@NAMES = ("GAPO[#*]"); +@DEFAULT_ARGS = (5, "{I:Prices LOW}", "{I:Prices HIGH}"); =head1 GT::Indicators::GAPO @@ -39,26 +40,15 @@ I think that the best way to use the results of this indicator is to look after the average or the moving average of the results, in order to have smooth data. =cut -sub new { - my $type = shift; - my $class = ref($type) || $type; - my ($args) = @_; - my $self = { 'args' => defined($args) ? $args : [5] }; - - $args->[0] = 5 if (! defined($args->[0])); - - return manage_object(\@NAMES, $self, $class, $self->{'args'}, ""); -} - sub initialize { my $self = shift; - $self->{'min'} = GT::Indicators::Generic::MinInPeriod->new([ $self->{'args'}[0] ], "LOW", $GET_LOW); - $self->{'max'} = GT::Indicators::Generic::MaxInPeriod->new([ $self->{'args'}[0] ], "HIGH", $GET_HIGH); + $self->{'min'} = GT::Indicators::Generic::MinInPeriod->new([ $self->{'args'}->get_arg_names(1), $self->{'args'}->get_arg_names(2) ]); + $self->{'max'} = GT::Indicators::Generic::MaxInPeriod->new([ $self->{'args'}->get_arg_names(1), $self->{'args'}->get_arg_names(3) ]); $self->add_indicator_dependency($self->{'min'}, 1); $self->add_indicator_dependency($self->{'max'}, 1); - $self->add_prices_dependency($self->{'args'}[0]); + $self->add_prices_dependency($self->{'args'}->get_arg_names(1)); } =head2 GT::Indicators::GAPO::calculate($calc, $day) @@ -68,7 +58,7 @@ my ($self, $calc, $i) = @_; my $indic = $calc->indicators; my $q = $calc->prices; - my $period = $self->{'args'}[0]; + my $period = $self->{'args'}->get_arg_names(1); my $min = $self->{'min'}; my $max = $self->{'max'}; my $min_name = $min->get_name; --- /bourse/cvsroot/GT/Indicators/REMA.pm 2004/01/07 18:49:14 1.1 +++ /bourse/cvsroot/GT/Indicators/REMA.pm 2004/03/02 21:36:51 1.2 @@ -63,14 +63,13 @@ sub initialize { my ($self) = @_; - $self->{'sma'} = GT::Indicators::SMA->new([$self->{'args'}->get_arg_names(1)], "SMA", $self->{'func'}); + $self->{'sma'} = GT::Indicators::SMA->new([$self->{'args'}->get_arg_names(1), $self->{'args'}->get_arg_names(3) ]); } sub calculate { my ($self, $calc, $i) = @_; my $nb = $self->{'args'}->get_arg_values($calc, $i, 1); my $lambda = $self->{'args'}->get_arg_values($calc, $i, 2); - my $getvalue = $self->{'func'}; my $name = $self->get_name; return if (! defined($nb)); @@ -83,9 +82,8 @@ return if (! $self->check_dependencies($calc, $i)); my $alpha = 2 / ($nb + 1); - - my $ema = &$getvalue($calc, $i - $nb + 1); - + + my $ema = $self->{'args'}->get_arg_values($calc, $i - $nb + 1, 3); if ($calc->indicators->is_available($name, $i-$nb)) { $ema = $calc->indicators->get($name, $i-$nb); @@ -109,9 +107,9 @@ } for (my $n = $bar - $nb + 1; $n <= $bar; $n++) { - $ema = ( $ema * (1-$alpha) ) + ( $alpha * &$getvalue($calc, $n) ); - $ema = $ema + ( (1+2*$lambda) * &$getvalue($calc, $n) ) - - ( $lambda * &$getvalue($calc, $n-1) ); + $ema = ( $ema * (1-$alpha) ) + ( $alpha * $self->{'args'}->get_arg_values($calc, $n, 3) ); + $ema = $ema + ( (1+2*$lambda) * $self->{'args'}->get_arg_values($calc, $n, 3) ) + - ( $lambda * $self->{'args'}->get_arg_values($calc, $n-1, 3) ); $ema = $ema / (1+$lambda); } @@ -130,7 +128,7 @@ for (my $n = $i - $nb + 1; $n <= $i; $n++) { $ema *= (1 - $alpha); - $ema += ($alpha * &$getvalue($calc, $n)); + $ema += ($alpha * $self->{'args'}->get_arg_values($calc, $n, 3)); } $calc->indicators->set($name, $i, $ema); --- /bourse/cvsroot/GT/Indicators/VHF.pm 2003/01/21 21:15:25 1.5 +++ /bourse/cvsroot/GT/Indicators/VHF.pm 2004/03/02 21:36:51 1.6 @@ -5,7 +5,7 @@ # version 2 or (at your option) any later version. use strict; -use vars qw(@ISA @NAMES); +use vars qw(@ISA @NAMES @DEFAULT_ARGS); use GT::Indicators; use GT::Indicators::Generic::MinInPeriod; @@ -13,7 +13,8 @@ use GT::Prices; @ISA = qw(GT::Indicators); -@NAMES = ("VHF[#1]"); +@NAMES = ("VHF[#*]"); +@DEFAULT_ARGS = (28, "{I:Prices CLOSE}"); =head1 GT::Indicators::VHF @@ -40,26 +41,15 @@ http://www.finance-net.com/apprendre/techniques/vhf.phtml =cut -sub new { - my $type = shift; - my $class = ref($type) || $type; - my ($args) = @_; - my $self = { 'args' => defined($args) ? $args : [28] }; - - $args->[0] = 28 if (! defined($args->[0])); - - return manage_object(\@NAMES, $self, $class, $self->{'args'}, ""); -} - sub initialize { my $self = shift; - $self->{'min'} = GT::Indicators::Generic::MinInPeriod->new([ $self->{'args'}[0] ], "LAST", $GET_LAST); - $self->{'max'} = GT::Indicators::Generic::MaxInPeriod->new([ $self->{'args'}[0] ], "LAST", $GET_LAST); + $self->{'min'} = GT::Indicators::Generic::MinInPeriod->new([ $self->{'args'}->get_arg_names(1), $self->{'args'}->get_arg_names(2) ]); + $self->{'max'} = GT::Indicators::Generic::MaxInPeriod->new([ $self->{'args'}->get_arg_names(1), $self->{'args'}->get_arg_names(2) ]); $self->add_indicator_dependency($self->{'min'}, 1); $self->add_indicator_dependency($self->{'max'}, 1); - $self->add_prices_dependency($self->{'args'}[0]); + $self->add_prices_dependency($self->{'args'}->get_arg_names(1)); } =head2 GT::Indicators::VHF::calculate($calc, $day) @@ -69,7 +59,7 @@ my ($self, $calc, $i) = @_; my $indic = $calc->indicators; my $prices = $calc->prices; - my $period = $self->{'args'}[0]; + my $period = $self->{'args'}->get_arg_names(1); my $min = $self->{'min'}; my $max = $self->{'max'}; my $min_name = $min->get_name; |