| 1 | # Copyright 2006, 2007, 2009, 2010, 2011 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::FRAMAalpha; | ||
| 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::FRAMAdimension; | ||
| 27 | |||
| 28 | |||
| 29 | sub longname { __('FRAMA - Alpha') } | ||
| 30 | sub shortname { __('FRAMA alpha') } | ||
| 31 | sub manual { __p('manual-node','Fractal Adaptive Moving Average') } | ||
| 32 | |||
| 33 | use constant | ||
| 34 | { type => 'indicator', | ||
| 35 | priority => -10, | ||
| 36 | units => 'ema_alpha', | ||
| 37 | # actually the minimum is 0.01 below, but show 0 | ||
| 38 | minimum => 0, | ||
| 39 | maximum => 1, | ||
| 40 | parameter_info => | ||
| 41 | App::Chart::Series::Derived::FRAMAdimension::parameter_info(), | ||
| 42 | }; | ||
| 43 | |||
| 44 | sub new { | ||
| 45 | my ($class, $parent, $N) = @_; | ||
| 46 | |||
| 47 | $N //= parameter_info()->[0]->{'default'}; | ||
| 48 | |||
| 49 | return $class->SUPER::new | ||
| 50 | (parent => $parent, | ||
| 51 | parameters => [ $N ], | ||
| 52 | arrays => { values => [] }, | ||
| 53 | array_aliases => { }); | ||
| 54 | } | ||
| 55 | *warmup_count = \&App::Chart::Series::Derived::FRAMAdimension::warmup_count; | ||
| 56 | |||
| 57 | sub proc { | ||
| 58 | my ($class, $N) = @_; | ||
| 59 | my $dim_proc = App::Chart::Series::Derived::FRAMAdimension->proc($N); | ||
| 60 | |||
| 61 | return sub { | ||
| 62 | my $dim = $dim_proc->(@_) // return undef; | ||
| 63 | return max(0.01, min(1.0, exp(-4.6*($dim-1)))); | ||
| 64 | }; | ||
| 65 | } | ||
| 66 | *fill_part = \&App::Chart::Series::Derived::WilliamsR::fill_part; | ||
| 67 | |||
| 68 | 1; | ||
| 69 | __END__ |