| 1 | package Finance::GeniusTrader::Indicators::Generic::If; | ||
| 2 | |||
| 3 | # Copyright 2000-2003 Raphaƫl Hertzog | ||
| 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); | ||
| 11 | |||
| 12 | use Finance::GeniusTrader::Indicators; | ||
| 13 | use Finance::GeniusTrader::Prices; | ||
| 14 | |||
| 15 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 16 | @NAMES = ("If[#*]"); | ||
| 17 | |||
| 18 | =head1 NAME | ||
| 19 | |||
| 20 | Finance::GeniusTrader::Indicators::Generic::If - Return a value or another depending on a signal | ||
| 21 | |||
| 22 | =head1 DESCRIPTION | ||
| 23 | |||
| 24 | This indicator takes three parameters. First a signal followed by two indicators. | ||
| 25 | if the signal is true it returns the value of the first indicator, otherwise it | ||
| 26 | returns the value of the second indicator. | ||
| 27 | |||
| 28 | =over | ||
| 29 | |||
| 30 | =item {S:Prices:Advance} {I:Generic:MaxInPeriod 5} {I:Generic:MinInPeriod 5} | ||
| 31 | |||
| 32 | =item {S:Generic:CrossOverUp {I:RSI} 80} {I:SAR} {I:Generic:MaxInPeriod 10} | ||
| 33 | |||
| 34 | =back | ||
| 35 | |||
| 36 | =cut | ||
| 37 | sub initialize { | ||
| 38 | my ($self) = @_; | ||
| 39 | |||
| 40 | } | ||
| 41 | |||
| 42 | sub calculate { | ||
| 43 | my ($self, $calc, $i) = @_; | ||
| 44 | my $name = $self->get_name; | ||
| 45 | my $value; | ||
| 46 | |||
| 47 | return if ($calc->indicators->is_available($name, $i)); | ||
| 48 | |||
| 49 | if ($self->{'args'}->get_arg_values($calc, $i, 1)) { | ||
| 50 | $value = $self->{'args'}->get_arg_values($calc, $i, 2); | ||
| 51 | } else { | ||
| 52 | $value = $self->{'args'}->get_arg_values($calc, $i, 3); | ||
| 53 | } | ||
| 54 | |||
| 55 | if (defined($value)) { | ||
| 56 | $calc->indicators->set($name, $i, $value); | ||
| 57 | } | ||
| 58 | } |