|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Math::Business::MACD;  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
3
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
6398
 | 
 use strict;  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
36
 | 
    | 
| 
4
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
6
 | 
 use warnings;  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
33
 | 
    | 
| 
5
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
5
 | 
 use Carp;  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
61
 | 
    | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
7
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
566
 | 
 use Math::Business::EMA;  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
815
 | 
    | 
| 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
11
 | 
0
 | 
 
 | 
 
 | 
  
0
  
 | 
  
0
  
 | 
0
 | 
 sub tag { (shift)->{tag} }  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub recommended {  | 
| 
14
 | 
0
 | 
 
 | 
 
 | 
  
0
  
 | 
  
0
  
 | 
0
 | 
     my $class = shift;  | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
16
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     $class->new(26, 12, 9);  | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub new {  | 
| 
20
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
  
0
  
 | 
1403
 | 
     my $class = shift;  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
22
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
     my $this = bless {  | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         slow_EMA => new Math::Business::EMA,  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         fast_EMA => new Math::Business::EMA,  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         trig_EMA => new Math::Business::EMA,  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         days     => 0,  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }, $class;  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
29
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     if( @_ == 3 ) {  | 
| 
30
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         $this->set_days(@_);  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
33
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     return $this;  | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub set_days {  | 
| 
37
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
  
0
  
 | 
6
 | 
     my $this = shift;  | 
| 
38
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
     my ($slow, $fast, $trig) = @_;  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
40
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
6
 | 
     croak "slow days must be a positive non-zero integers" if $slow <= 0;  | 
| 
41
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     croak "fast days must be a positive non-zero integers" if $fast <= 0;  | 
| 
42
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     croak "trig days must be a positive non-zero integers" if $trig <= 0;  | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
44
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
     $this->{days} = 1;  | 
| 
45
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
46
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
     $this->{slow_EMA}->set_days($slow);  | 
| 
47
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     $this->{fast_EMA}->set_days($fast);  | 
| 
48
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
     $this->{trig_EMA}->set_days($trig);  | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
50
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     $this->{tag} = "MACD($fast,$slow,$trig)";  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
53
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
  
0
  
 | 
14
 | 
 sub query_trig_ema { my $this = shift; return $this->{trig_EMA}->query }  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
    | 
| 
54
 | 
42
 | 
 
 | 
 
 | 
  
42
  
 | 
  
0
  
 | 
46
 | 
 sub query_slow_ema { my $this = shift; return $this->{slow_EMA}->query }  | 
| 
 
 | 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
95
 | 
    | 
| 
55
 | 
42
 | 
 
 | 
 
 | 
  
42
  
 | 
  
0
  
 | 
41
 | 
 sub query_fast_ema { my $this = shift; return $this->{fast_EMA}->query }  | 
| 
 
 | 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
103
 | 
    | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub query_histogram {  | 
| 
58
 | 
0
 | 
 
 | 
 
 | 
  
0
  
 | 
  
0
  
 | 
0
 | 
     my $this = shift;  | 
| 
59
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
60
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     my $m = $this->query;  | 
| 
61
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     my $t = $this->query_trig_ema;  | 
| 
62
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
63
 | 
0
 | 
  
  0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
0
 | 
     return unless defined($m) and defined($t);  | 
| 
64
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     return $m - $t;  | 
| 
65
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
66
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub query {  | 
| 
68
 | 
42
 | 
 
 | 
 
 | 
  
42
  
 | 
  
0
  
 | 
48
 | 
     my $this = shift;  | 
| 
69
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
70
 | 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
69
 | 
     my $f = $this->query_fast_ema;  | 
| 
71
 | 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
78
 | 
     my $s = $this->query_slow_ema;  | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
73
 | 
42
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
184
 | 
     return unless defined($f) and defined($s);  | 
| 
74
 | 
16
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
36
 | 
     if( wantarray ) {  | 
| 
75
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         my $m = $f-$s;  | 
| 
76
 | 
0
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         my $t = $this->query_trig_ema; return unless defined $t;  | 
| 
 
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
    | 
| 
77
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         my $h = $m-$t;  | 
| 
78
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
79
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         return ( $m, $f, $s, $t, $h );  | 
| 
80
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
81
 | 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
39
 | 
     return $f - $s;  | 
| 
82
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
83
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
84
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub insert {  | 
| 
85
 | 
39
 | 
 
 | 
 
 | 
  
39
  
 | 
  
0
  
 | 
109
 | 
     my $this  = shift;  | 
| 
86
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
87
 | 
39
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
86
 | 
     croak "You must set the number of days before you try to insert" if not $this->{days};  | 
| 
88
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
89
 | 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
87
 | 
     while( defined( my $value = shift ) ) {  | 
| 
90
 | 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
102
 | 
         $this->{slow_EMA}->insert($value);  | 
| 
91
 | 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
102
 | 
         $this->{fast_EMA}->insert($value);  | 
| 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
93
 | 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
70
 | 
         my $m = $this->query;  | 
| 
94
 | 
39
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
172
 | 
         $this->{trig_EMA}->insert( $m ) if defined($m);  | 
| 
95
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
96
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
98
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |