| 1 | package Finance::GeniusTrader::Indicators::CMO; | ||
| 2 | |||
| 3 | # Copyright 2002 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::Indicators; | ||
| 13 | use Finance::GeniusTrader::Prices; | ||
| 14 | use Finance::GeniusTrader::Tools qw(:math); | ||
| 15 | use Finance::GeniusTrader::ArgsTree; | ||
| 16 | use Finance::GeniusTrader::Indicators::Generic::SumUpDiffs; | ||
| 17 | use Finance::GeniusTrader::Indicators::Generic::SumDownDiffs; | ||
| 18 | |||
| 19 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 20 | @NAMES = ("CMO[#*]"); | ||
| 21 | @DEFAULT_ARGS = (10, "{I:Prices CLOSE}"); | ||
| 22 | |||
| 23 | =head1 NAME | ||
| 24 | |||
| 25 | Finance::GeniusTrader::Indicators::CMO - Chande Moment Oscillator | ||
| 26 | |||
| 27 | =head1 DESCRIPTION | ||
| 28 | |||
| 29 | The CMO indicator was developed by Trushar Chande and presented 1994 | ||
| 30 | in the book "The New Technical Trader". It can be used as an oscillator | ||
| 31 | (CMO > 50 => overbought, CMO < -50 => oversold) or as a trend indicator | ||
| 32 | (the higher/lower the CMO, the stronger the trend) | ||
| 33 | |||
| 34 | CMO = 100 * (SumUp-SumDown) / (SumUp+SumDown) | ||
| 35 | |||
| 36 | |||
| 37 | =head2 Parameters | ||
| 38 | |||
| 39 | =over | ||
| 40 | |||
| 41 | =item Period (default 10) | ||
| 42 | |||
| 43 | This argument is used to calculate the SumUp and SumDown. | ||
| 44 | |||
| 45 | =back | ||
| 46 | |||
| 47 | =head2 Creation | ||
| 48 | |||
| 49 | Finance::GeniusTrader::Indicators::CMO->new() | ||
| 50 | |||
| 51 | =head2 Links | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | |||
| 56 | sub initialize { | ||
| 57 | my $self = shift; | ||
| 58 | |||
| 59 | $self->{'sumup'} = Finance::GeniusTrader::Indicators::Generic::SumUpDiffs->new( [ $self->{'args'}->get_arg_names(1), | ||
| 60 | $self->{'args'}->get_arg_names(2) ] ); | ||
| 61 | $self->{'sumdown'} = Finance::GeniusTrader::Indicators::Generic::SumDownDiffs->new( [ $self->{'args'}->get_arg_names(1), | ||
| 62 | $self->{'args'}->get_arg_names(2) ] ); | ||
| 63 | |||
| 64 | } | ||
| 65 | |||
| 66 | sub calculate { | ||
| 67 | my ($self, $calc, $i) = @_; | ||
| 68 | my $indic = $calc->indicators; | ||
| 69 | my $name = $self->get_name; | ||
| 70 | my $sumup_name = $self->{'sumup'}->get_name; | ||
| 71 | my $sumdown_name = $self->{'sumdown'}->get_name; | ||
| 72 | my $length = $self->{'args'}->get_arg_values($calc, $i, 1); | ||
| 73 | |||
| 74 | # Calculate the depencies | ||
| 75 | $self->remove_volatile_dependencies(); | ||
| 76 | $self->add_volatile_indicator_dependency( $self->{'sumup'}, $length ); | ||
| 77 | $self->add_volatile_indicator_dependency( $self->{'sumdown'}, $length ); | ||
| 78 | |||
| 79 | return if ($calc->indicators->is_available($name, $i)); | ||
| 80 | return if (! $self->check_dependencies($calc, $i) ); | ||
| 81 | |||
| 82 | my $sumup = $indic->get($sumup_name, $i); | ||
| 83 | my $sumdown = $indic->get($sumdown_name, $i); | ||
| 84 | if ($sumup + $sumdown == 0) | ||
| 85 | { | ||
| 86 | $sumup += 0.00001; | ||
| 87 | } | ||
| 88 | |||
| 89 | my $cmo = 100 * ($sumup - $sumdown) / ($sumup + $sumdown); | ||
| 90 | |||
| 91 | $indic->set($name, $i, $cmo); | ||
| 92 | |||
| 93 | } | ||
| 94 | |||
| 95 | 1; |