| 1 | # Copyright 2006, 2007, 2009, 2010 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Chart. | ||
| 4 | # | ||
| 5 | # Chart is free software; you can redistribute it and/or modify it under the | ||
| 6 | # terms of the GNU General Public License as published by the Free Software | ||
| 7 | # Foundation; either version 3, or (at your option) any later version. | ||
| 8 | # | ||
| 9 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 12 | # details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | |||
| 17 | package App::Chart::Series::Derived::Coppock; | ||
| 18 | use 5.010; | ||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | use List::Util qw(min max); | ||
| 22 | use Locale::TextDomain ('App-Chart'); | ||
| 23 | |||
| 24 | use base 'App::Chart::Series::Indicator'; | ||
| 25 | use App::Chart::Series::Derived::ROC; | ||
| 26 | use App::Chart::Series::Derived::WMA; | ||
| 27 | |||
| 28 | sub longname { __('Coppock Curve') } | ||
| 29 | sub shortname { __('Coppock') } | ||
| 30 | sub manual { __p('manual-node','Coppock Curve') } | ||
| 31 | |||
| 32 | use constant | ||
| 33 | { type => 'indicator', | ||
| 34 | units => 'roc_percent', | ||
| 35 | hlines => [ 0 ], | ||
| 36 | parameter_info => App::Chart::Series::Derived::Momentum::parameter_info(), | ||
| 37 | }; | ||
| 38 | |||
| 39 | my $N1 = 11; | ||
| 40 | my $N2 = 14; | ||
| 41 | my $smooth = 10; | ||
| 42 | |||
| 43 | sub new { | ||
| 44 | my ($class, $parent) = @_; | ||
| 45 | |||
| 46 | return $class->SUPER::new | ||
| 47 | (parent => $parent, | ||
| 48 | parameters => [ ], | ||
| 49 | arrays => { values => [] }); | ||
| 50 | } | ||
| 51 | |||
| 52 | sub proc { | ||
| 53 | my ($self_or_class) = @_; | ||
| 54 | |||
| 55 | my $roc1_proc = App::Chart::Series::Derived::ROC->proc ($N1); | ||
| 56 | my $roc2_proc = App::Chart::Series::Derived::ROC->proc ($N2); | ||
| 57 | my $wma_proc = App::Chart::Series::Derived::WMA->proc ($smooth); | ||
| 58 | |||
| 59 | return sub { | ||
| 60 | my ($value) = @_; | ||
| 61 | my $roc1 = $roc1_proc->($value); | ||
| 62 | my $roc2 = $roc2_proc->($value); | ||
| 63 | if (! defined $roc1 || ! defined $roc2) { return undef; } | ||
| 64 | return $wma_proc->($roc1 + $roc2); | ||
| 65 | }; | ||
| 66 | } | ||
| 67 | sub warmup_count { | ||
| 68 | my ($class_or_self) = @_; | ||
| 69 | return $smooth - 1 + max($N1, $N2); | ||
| 70 | } | ||
| 71 | |||
| 72 | 1; | ||
| 73 | __END__ |