| 1 | package Finance::GeniusTrader::Systems::Stochastic; | ||
| 2 | |||
| 3 | # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber | ||
| 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 | use strict; | ||
| 8 | use vars qw(@ISA @NAMES); | ||
| 9 | |||
| 10 | use Finance::GeniusTrader::Prices; | ||
| 11 | use Finance::GeniusTrader::Systems; | ||
| 12 | use Finance::GeniusTrader::Indicators::STO; | ||
| 13 | |||
| 14 | @ISA = qw(Finance::GeniusTrader::Systems); | ||
| 15 | @NAMES = ("Stochastic[#1,#2,#3,#4]"); | ||
| 16 | |||
| 17 | =pod | ||
| 18 | |||
| 19 | =head1 Stochastic | ||
| 20 | |||
| 21 | =cut | ||
| 22 | |||
| 23 | sub new { | ||
| 24 | my $type = shift; | ||
| 25 | my $class = ref($type) || $type; | ||
| 26 | my $args = shift; | ||
| 27 | |||
| 28 | my $self = { "args" => defined($args) ? $args : [9, 3, 3, 3] }; | ||
| 29 | |||
| 30 | return manage_object(\@NAMES, $self, $class, $self->{'args'}, ""); | ||
| 31 | } | ||
| 32 | |||
| 33 | sub initialize { | ||
| 34 | my ($self) = @_; | ||
| 35 | |||
| 36 | $self->{'sto'} = Finance::GeniusTrader::Indicators::STO->new($self->{'args'}); | ||
| 37 | |||
| 38 | $self->{'allow_multiple'} = 0; | ||
| 39 | |||
| 40 | $self->add_indicator_dependency($self->{'sto'}, 1);; | ||
| 41 | } | ||
| 42 | |||
| 43 | |||
| 44 | sub long_signal { | ||
| 45 | my ($self, $calc, $i) = @_; | ||
| 46 | my $indic = $calc->indicators; | ||
| 47 | |||
| 48 | return 0 if (!$self->check_dependencies($calc, $i)); | ||
| 49 | |||
| 50 | if ( ( $indic->get($self->{'sto'}->get_name(2), $i) < 80 ) && | ||
| 51 | ( $indic->get($self->{'sto'}->get_name(1), $i) > | ||
| 52 | $indic->get($self->{'sto'}->get_name(3), $i) ) | ||
| 53 | ) | ||
| 54 | { | ||
| 55 | return 1; | ||
| 56 | } | ||
| 57 | return 0; | ||
| 58 | } | ||
| 59 | |||
| 60 | sub short_signal { | ||
| 61 | my ($self, $calc, $i) = @_; | ||
| 62 | my $indic = $calc->indicators; | ||
| 63 | |||
| 64 | return 0 if (!$self->check_dependencies($calc, $i)); | ||
| 65 | |||
| 66 | if ( ( $indic->get($self->{'sto'}->get_name(2), $i) > 20 ) && | ||
| 67 | ( $indic->get($self->{'sto'}->get_name(1), $i) < | ||
| 68 | $indic->get($self->{'sto'}->get_name(3), $i) ) | ||
| 69 | ) | ||
| 70 | { | ||
| 71 | return 1; | ||
| 72 | } | ||
| 73 | return 0; | ||
| 74 | } |