| 1 | package Finance::GeniusTrader::Indicators::CHAIKIN; | ||
| 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 @DEFAULT_ARGS); | ||
| 9 | |||
| 10 | use Finance::GeniusTrader::Indicators; | ||
| 11 | use Finance::GeniusTrader::Indicators::ADL; | ||
| 12 | use Finance::GeniusTrader::Indicators::EMA; | ||
| 13 | use Finance::GeniusTrader::Prices; | ||
| 14 | |||
| 15 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 16 | @NAMES = ("CHAIKIN[#1,#2]"); | ||
| 17 | @DEFAULT_ARGS = (3, 10); | ||
| 18 | |||
| 19 | =head2 Finance::GeniusTrader::Indicators::CHAIKIN | ||
| 20 | |||
| 21 | =head2 Overview | ||
| 22 | |||
| 23 | The Chaikin Oscillator is a moving average oscillator based on the Accumulation/Distribution indicator (ADL.pm). | ||
| 24 | |||
| 25 | =head2 Calculation | ||
| 26 | |||
| 27 | The formula is the difference between the 3-day exponential moving average and the 10-day exponential moving average of the Accumulation/Distribution Line. | ||
| 28 | |||
| 29 | =head2 Examples | ||
| 30 | |||
| 31 | Finance::GeniusTrader::Indicators::CHAIKIN->new() | ||
| 32 | Finance::GeniusTrader::Indicators::CHAIKIN->new([3, 10]) | ||
| 33 | |||
| 34 | =head2 Links | ||
| 35 | |||
| 36 | http://www.stockcharts.com/education/What/IndicatorAnalysis/indic_ChaikinOscillator.html | ||
| 37 | http://www.equis.com/free/taaz/chaikinosc.html | ||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | sub initialize { | ||
| 42 | my $self = shift; | ||
| 43 | |||
| 44 | $self->{'ema1'} = Finance::GeniusTrader::Indicators::EMA->new([ $self->{'args'}->get_arg_names(1), "{I:ADL}"] ); | ||
| 45 | $self->{'ema2'} = Finance::GeniusTrader::Indicators::EMA->new([ $self->{'args'}->get_arg_names(2), "{I:ADL}"] ); | ||
| 46 | |||
| 47 | $self->add_indicator_dependency($self->{'ema1'}, 1); | ||
| 48 | $self->add_indicator_dependency($self->{'ema2'}, 1); | ||
| 49 | } | ||
| 50 | |||
| 51 | =head2 Finance::GeniusTrader::Indicators::CHAIKIN::calculate($calc, $day) | ||
| 52 | |||
| 53 | =cut | ||
| 54 | sub calculate { | ||
| 55 | my ($self, $calc, $i) = @_; | ||
| 56 | my $indic = $calc->indicators; | ||
| 57 | my $ema1 = $self->{'ema1'}; | ||
| 58 | my $ema2 = $self->{'ema2'}; | ||
| 59 | my $ema1_name = $ema1->get_name; | ||
| 60 | my $ema2_name = $ema2->get_name; | ||
| 61 | my $chaikin_name = $self->get_name(0); | ||
| 62 | |||
| 63 | return if ($indic->is_available($chaikin_name, $i)); | ||
| 64 | return if (! $self->check_dependencies($calc, $i)); | ||
| 65 | |||
| 66 | # Get both EMA value | ||
| 67 | my $ema1_value = $indic->get($ema1_name, $i); | ||
| 68 | my $ema2_value = $indic->get($ema2_name, $i); | ||
| 69 | |||
| 70 | # Calculate the Chaikin Oscillator | ||
| 71 | my $chaikin_value = $ema1_value - $ema2_value; | ||
| 72 | |||
| 73 | # Return the results | ||
| 74 | $indic->set($chaikin_name, $i, $chaikin_value); | ||
| 75 | } | ||
| 76 | |||
| 77 | 1; |