| 1 | package Finance::GeniusTrader::CloseStrategy::Stop::BasedOnIndicators; | ||
| 2 | |||
| 3 | # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber | ||
| 4 | # Modified 2004 by Oliver Bossert | ||
| 5 | # This file is distributed under the terms of the General Public License | ||
| 6 | # version 2 or (at your option) any later version. | ||
| 7 | |||
| 8 | # Standards-Version: 1.0 | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 12 | |||
| 13 | use Finance::GeniusTrader::CloseStrategy; | ||
| 14 | use Finance::GeniusTrader::Eval; | ||
| 15 | use Finance::GeniusTrader::Prices; | ||
| 16 | use Finance::GeniusTrader::Tools qw(:generic); | ||
| 17 | |||
| 18 | @ISA = qw(Finance::GeniusTrader::CloseStrategy); | ||
| 19 | @NAMES = ("BasedOnIndicators[#*]"); | ||
| 20 | @DEFAULT_ARGS = ("{I:SMA}", "{I:SMA}", "{I:Prices CLOSE}"); | ||
| 21 | |||
| 22 | =head1 Finance::GeniusTrader::CloseStrategy::Stop::BasedOnIndicators | ||
| 23 | |||
| 24 | =head2 Overview | ||
| 25 | |||
| 26 | This strategy end up a position once prices have crossed the trailing stop | ||
| 27 | determined by indicators. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | sub initialize { | ||
| 32 | my ($self) = @_; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub get_indicative_long_stop { | ||
| 36 | my ($self, $calc, $i, $order, $pf_manager, $sys_manager) = @_; | ||
| 37 | |||
| 38 | return 0 if (! $self->check_dependencies($calc, $i)); | ||
| 39 | my $indi = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 40 | my $price = $self->{'args'}->get_arg_values($calc, $i, 3); | ||
| 41 | |||
| 42 | if ($indi < $price) { | ||
| 43 | return $indi; | ||
| 44 | } else { | ||
| 45 | return 0; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | sub get_indicative_short_stop { | ||
| 50 | my ($self, $calc, $i, $order, $pf_manager, $sys_manager) = @_; | ||
| 51 | |||
| 52 | return 0 if (! $self->check_dependencies($calc, $i)); | ||
| 53 | my $indi = $self->{'args'}->get_arg_values($calc, $i, 2); | ||
| 54 | my $price = $self->{'args'}->get_arg_values($calc, $i, 3); | ||
| 55 | |||
| 56 | if ($indi > $price) { | ||
| 57 | return $indi; | ||
| 58 | } else { | ||
| 59 | return 0; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | sub long_position_opened { | ||
| 64 | my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_; | ||
| 65 | |||
| 66 | return; | ||
| 67 | } | ||
| 68 | |||
| 69 | sub short_position_opened { | ||
| 70 | my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_; | ||
| 71 | |||
| 72 | return; | ||
| 73 | } | ||
| 74 | |||
| 75 | sub manage_long_position { | ||
| 76 | my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_; | ||
| 77 | |||
| 78 | return if (! $self->check_dependencies($calc, $i)); | ||
| 79 | my $indi = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 80 | my $price = $self->{'args'}->get_arg_values($calc, $i, 3); | ||
| 81 | |||
| 82 | if ($indi < $price) { | ||
| 83 | $position->set_stop($indi); | ||
| 84 | } | ||
| 85 | |||
| 86 | return; | ||
| 87 | } | ||
| 88 | |||
| 89 | sub manage_short_position { | ||
| 90 | my ($self, $calc, $i, $position, $pf_manager, $sys_manager) = @_; | ||
| 91 | |||
| 92 | return if (! $self->check_dependencies($calc, $i)); | ||
| 93 | my $indi = $self->{'args'}->get_arg_values($calc, $i, 2); | ||
| 94 | my $price = $self->{'args'}->get_arg_values($calc, $i, 3); | ||
| 95 | |||
| 96 | if ($indi > $price) { | ||
| 97 | $position->set_stop($indi); | ||
| 98 | } | ||
| 99 | |||
| 100 | return; | ||
| 101 | } | ||
| 102 | |||
| 103 | 1; |