| 1 | # Copyright 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::Inertia; | ||
| 18 | use 5.010; | ||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | use Carp; | ||
| 22 | use List::Util qw(min max); | ||
| 23 | use Locale::TextDomain ('App-Chart'); | ||
| 24 | |||
| 25 | use base 'App::Chart::Series::Indicator'; | ||
| 26 | use App::Chart::Series::Derived::RVI; | ||
| 27 | use App::Chart::Series::Derived::EPMA; | ||
| 28 | use App::Chart::Series::Derived::WilliamsR; | ||
| 29 | |||
| 30 | |||
| 31 | # http://trader.online.pl/MSZ/e-w-Inertia.html | ||
| 32 | # | ||
| 33 | # http://www.fmlabs.com/reference/Inertia.htm | ||
| 34 | # Formula, some description. | ||
| 35 | # | ||
| 36 | # http://www.prophet.net/analyze/popglossary.jsp?studyid=INERT | ||
| 37 | # Sample DELL from 2001/2. | ||
| 38 | # | ||
| 39 | # http://store.traders.com/-v13-c09-refinin-pdf.html | ||
| 40 | # Dorsey TASC 1995 for sale. | ||
| 41 | # | ||
| 42 | |||
| 43 | sub longname { __('Inertia (smoothed RVI)') } | ||
| 44 | sub shortname { __('Inertia') } | ||
| 45 | sub manual { __p('manual-node','Inertia') } | ||
| 46 | |||
| 47 | use constant | ||
| 48 | { hlines => [ 40, 50, 60 ], | ||
| 49 | type => 'indicator', | ||
| 50 | units => 'percentage', | ||
| 51 | minimum => 0, | ||
| 52 | maximum => 100, | ||
| 53 | parameter_info => [ { name => __('Stddev Days'), | ||
| 54 | key => 'rvi_stddev_days', # per RVI.pm | ||
| 55 | type => 'integer', | ||
| 56 | minimum => 1, | ||
| 57 | default => 10 }, | ||
| 58 | { name => __('Smooth Days'), | ||
| 59 | key => 'rvi_smooth_days', # per RVI.pm | ||
| 60 | type => 'float', | ||
| 61 | minimum => 1, | ||
| 62 | default => 14, | ||
| 63 | decimals => 0, | ||
| 64 | step => 1 }, | ||
| 65 | { name => __('LSQMA Days'), | ||
| 66 | key => 'inertia_lsqma_days', | ||
| 67 | type => 'integer', | ||
| 68 | minimum => 1, | ||
| 69 | default => 20 }, | ||
| 70 | ], | ||
| 71 | }; | ||
| 72 | |||
| 73 | sub new { | ||
| 74 | my ($class, $parent, $N_stddev, $N_smooth, $N_lsqma) = @_; | ||
| 75 | |||
| 76 | $N_stddev //= parameter_info()->[0]->{'default'}; | ||
| 77 | ($N_stddev > 0) || croak "Inertia bad N_stddev: $N_stddev"; | ||
| 78 | |||
| 79 | $N_smooth //= parameter_info()->[1]->{'default'}; | ||
| 80 | ($N_smooth > 0) || croak "Inertia bad N_smooth: $N_smooth"; | ||
| 81 | |||
| 82 | $N_lsqma //= parameter_info()->[1]->{'default'}; | ||
| 83 | ($N_lsqma > 0) || croak "Inertia bad N_lsqma: $N_lsqma"; | ||
| 84 | |||
| 85 | return $class->SUPER::new | ||
| 86 | (parent => $parent, | ||
| 87 | parameters => [ $N_stddev, $N_smooth, $N_lsqma ], | ||
| 88 | arrays => { values => [] }, | ||
| 89 | array_aliases => { }); | ||
| 90 | } | ||
| 91 | *fill_part = \&App::Chart::Series::Derived::WilliamsR::fill_part; | ||
| 92 | |||
| 93 | sub warmup_count { | ||
| 94 | my ($class_or_self, $N_stddev, $N_smooth, $N_lsqma) = @_; | ||
| 95 | return (App::Chart::Series::Derived::RVI->warmup_count($N_stddev, $N_smooth) | ||
| 96 | + App::Chart::Series::Derived::EPMA->warmup_count($N_lsqma)); | ||
| 97 | } | ||
| 98 | |||
| 99 | sub proc { | ||
| 100 | my ($class_or_self, $N_stddev, $N_smooth, $N_lsqma) = @_; | ||
| 101 | my $rvi_proc = App::Chart::Series::Derived::RVI->proc($N_stddev, $N_smooth); | ||
| 102 | my $lsqma_proc = App::Chart::Series::Derived::EPMA->proc($N_lsqma); | ||
| 103 | return sub { | ||
| 104 | my $rvi = $rvi_proc->(@_) // return; | ||
| 105 | return $lsqma_proc->($rvi); | ||
| 106 | }; | ||
| 107 | } | ||
| 108 | |||
| 109 | 1; | ||
| 110 | __END__ |