| 1 | package Finance::GeniusTrader::Signals::Swing::TrendEnding; | ||
| 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::Signals; | ||
| 12 | use Finance::GeniusTrader::Signals::Swing::Trend; | ||
| 13 | |||
| 14 | @ISA = qw(Finance::GeniusTrader::Signals); | ||
| 15 | @NAMES = ("TrendUpEnding", "TrendDownEnding"); | ||
| 16 | |||
| 17 | =pod | ||
| 18 | |||
| 19 | =head1 Finance::GeniusTrader::Signals::Swing::TrendUpEnding | ||
| 20 | |||
| 21 | An up-trend is going on and a little candle is constated. The trend may be | ||
| 22 | ending ... | ||
| 23 | |||
| 24 | =cut | ||
| 25 | |||
| 26 | sub new { | ||
| 27 | my $type = shift; | ||
| 28 | my $class = ref($type) || $type; | ||
| 29 | my $self = { "args" => [] }; | ||
| 30 | |||
| 31 | return manage_object(\@NAMES, $self, $class, $self->{'args'}, ""); | ||
| 32 | } | ||
| 33 | |||
| 34 | sub initialize { | ||
| 35 | my $self = shift; | ||
| 36 | |||
| 37 | $self->{'trend'} = Finance::GeniusTrader::Signals::Swing::Trend->new(); | ||
| 38 | |||
| 39 | $self->add_signal_dependency($self->{'trend'}, 2); | ||
| 40 | $self->add_prices_dependency(3); | ||
| 41 | } | ||
| 42 | |||
| 43 | sub detect { | ||
| 44 | my ($self, $calc, $i) = @_; | ||
| 45 | my $q = $calc->prices; | ||
| 46 | my $sig = $calc->signals; | ||
| 47 | my $trend_up_name = $self->{'trend'}->get_name(0); | ||
| 48 | my $trend_down_name = $self->{'trend'}->get_name(1); | ||
| 49 | |||
| 50 | return if (! $calc->signals->is_available($trend_up_name, $i)); | ||
| 51 | return if (! $self->check_dependencies($calc, $i)); | ||
| 52 | |||
| 53 | my $max = $q->at($i-2)->[$HIGH] - $q->at($i-2)->[$LOW]; | ||
| 54 | if ($q->at($i-1)->[$HIGH] - $q->at($i-1)->[$LOW] > $max) | ||
| 55 | { | ||
| 56 | $max = $q->at($i-1)->[$HIGH] - $q->at($i-1)->[$LOW]; | ||
| 57 | } | ||
| 58 | |||
| 59 | if ( # Trend up | ||
| 60 | $sig->get($trend_up_name, $i - 1) && | ||
| 61 | # Last candle less than a third of the biggest candle | ||
| 62 | ($q->at($i)->[$HIGH] - $q->at($i)->[$LOW] < $max / 3) | ||
| 63 | ) | ||
| 64 | { | ||
| 65 | $sig->set($self->get_name(0), $i, 1); | ||
| 66 | } else { | ||
| 67 | $sig->set($self->get_name(0), $i, 0); | ||
| 68 | } | ||
| 69 | |||
| 70 | if ( # Trend down | ||
| 71 | $sig->get($trend_down_name, $i - 1) && | ||
| 72 | # Last candle less than a third of the biggest candle | ||
| 73 | ($q->at($i)->[$HIGH] - $q->at($i)->[$LOW] < $max / 3) | ||
| 74 | ) | ||
| 75 | { | ||
| 76 | $sig->set($self->get_name(1), $i, 1); | ||
| 77 | return 1; | ||
| 78 | } else { | ||
| 79 | $sig->set($self->get_name(1), $i, 0); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | 1; |