| 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::PVT; | ||
| 18 | use 5.010; | ||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | use Carp; | ||
| 22 | use List::Util qw(min max); | ||
| 23 | use Locale::TextDomain 1.17; # for __p() | ||
| 24 | use Locale::TextDomain ('App-Chart'); | ||
| 25 | |||
| 26 | use base 'App::Chart::Series::Indicator'; | ||
| 27 | use App::Chart::Series::Derived::OBV; | ||
| 28 | |||
| 29 | # http://www.incrediblecharts.com/indicators/price_and_volume_trend.php | ||
| 30 | # Including sample chart of ANZ.AX from Oct 2000. | ||
| 31 | # | ||
| 32 | |||
| 33 | |||
| 34 | sub longname { __('PVT - Price Volume Trend') } | ||
| 35 | sub shortname { __('PVT') } | ||
| 36 | sub manual { __p('manual-node','Price and Volume Trend') } | ||
| 37 | |||
| 38 | use constant | ||
| 39 | { type => 'indicator', | ||
| 40 | units => 'PVT', | ||
| 41 | parameter_info => [], | ||
| 42 | }; | ||
| 43 | |||
| 44 | sub new { | ||
| 45 | my ($class, $parent) = @_; | ||
| 46 | |||
| 47 | return $class->SUPER::new | ||
| 48 | (parent => $parent, | ||
| 49 | arrays => { values => [] }, | ||
| 50 | array_aliases => { }); | ||
| 51 | } | ||
| 52 | *fill_part = \&App::Chart::Series::Derived::OBV::fill_part; | ||
| 53 | |||
| 54 | sub proc { | ||
| 55 | my ($self) = @_; | ||
| 56 | my $parent = $self->parent; | ||
| 57 | my $pv = $parent->array('volumes') || []; | ||
| 58 | sub { | ||
| 59 | my ($i, $value, $i_prev, $value_prev) = @_; | ||
| 60 | if ($value_prev == 0) { | ||
| 61 | return 0; | ||
| 62 | } | ||
| 63 | my $volume = $pv->[$i] // 0; | ||
| 64 | return $volume * ($value - $value_prev) / $value_prev; | ||
| 65 | }; | ||
| 66 | } | ||
| 67 | |||
| 68 | 1; | ||
| 69 | __END__ |