| 1 | package Finance::GeniusTrader::Analyzers::Consec; | ||
| 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::Analyzers; | ||
| 13 | use Finance::GeniusTrader::Calculator; | ||
| 14 | |||
| 15 | @ISA = qw(Finance::GeniusTrader::Analyzers); | ||
| 16 | @NAMES = ("Consec[#*]"); | ||
| 17 | @DEFAULT_ARGS = ("{A:Costs}"); | ||
| 18 | |||
| 19 | =head1 NAME | ||
| 20 | |||
| 21 | Finance::GeniusTrader::Analyzers::Consec - Maximum of consecutive nonzero-values | ||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | Calculates the Average of Arg1 | ||
| 26 | |||
| 27 | =head2 Parameters | ||
| 28 | |||
| 29 | First argument: Array reference to be averaged | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | sub initialize { | ||
| 34 | 1; | ||
| 35 | } | ||
| 36 | |||
| 37 | sub calculate { | ||
| 38 | my ($self, $calc, $last, $first, $portfolio) = @_; | ||
| 39 | my $name = $self->get_name; | ||
| 40 | |||
| 41 | if ( !defined($portfolio) ) { | ||
| 42 | $portfolio = $calc->{'pf'}; | ||
| 43 | } | ||
| 44 | if ( !defined($first) ) { | ||
| 45 | $first = $calc->{'first'}; | ||
| 46 | } | ||
| 47 | if ( !defined($last) ) { | ||
| 48 | $last = $calc->{'last'}; | ||
| 49 | } | ||
| 50 | |||
| 51 | my $array = $self->{'args'}->get_arg_values($calc, $last, 1); | ||
| 52 | |||
| 53 | my $max = 0; | ||
| 54 | my $anz = 0; | ||
| 55 | foreach my $f (@{$array}) | ||
| 56 | { | ||
| 57 | if ($f != 0) { | ||
| 58 | $anz++; | ||
| 59 | } else { | ||
| 60 | $max = $anz if ($anz > $max); | ||
| 61 | $anz = 0; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | $calc->indicators->set($name, $last, $max); | ||
| 66 | } | ||
| 67 | |||
| 68 | 1; |