| 1 | package Math::Business::DMI; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Math::Business::ATR; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 3 | 1; | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub tag { (shift)->{tag} } | ||||||||||||||||||||||||||||||
|
Subroutine
tag: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | sub recommended { | ||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
recommended: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 4 | $class->new(14); | |||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | sub new { | ||||||||||||||||||||||||||||||||
| 20 | 4 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 21 | 4 | my $this = bless { | |||||||||||||||||||||||||||||||
| 22 | ATR => new Math::Business::ATR, | ||||||||||||||||||||||||||||||||
| 23 | }, $class; | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 4 | my $days = shift; | |||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | if( defined $days ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 27 | 4 | $this->set_days( $days ); | |||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 4 | return $this; | |||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | sub set_days { | ||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
set_days: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 35 | 4 | my $arg = int(shift); | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | croak "days must be a positive non-zero integer" if $arg <= 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 4 | $this->{ATR}->set_days($arg); | |||||||||||||||||||||||||||||||
| 40 | 4 | $this->{days} = $arg; | |||||||||||||||||||||||||||||||
| 41 | 4 | $this->{R} = ($arg-1)/$arg; | |||||||||||||||||||||||||||||||
| 42 | 4 | $this->{R1} = 1/$arg; | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 4 | $this->{tag} = "DMI($this->{days})"; | |||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | sub insert { | ||||||||||||||||||||||||||||||||
| 48 | 1109 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
insert: called CC=18 SCAR=29.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 1109 | my $y_point = $this->{y}; | |||||||||||||||||||||||||||||||
| 51 | 1109 | ▶ | while( defined( my $point = shift ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | 1112 | ▶ | croak "insert takes three tuple (high, low, close)" unless ref $point eq "ARRAY" and @$point == 3; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $point eq "ARRAY" and @$point == 3
MC/DC0%0/2
ref $point eq "ARRAY" and @$point == 3
ref $point eq "ARRAY"
@$point == 3
Truth table33%1/3
A and B
A= ref $point eq "ARRAY"B= @$point == 3
| |||||||||||||||||||||||||||||||||
| 53 | 1112 | my ($t_high, $t_low, $t_close) = @$point; | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 1112 | ▶ | if( defined $y_point ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | 1108 | my $atr = $this->{ATR}; | |||||||||||||||||||||||||||||||
| 57 | 1108 | $atr->insert($point); | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 1108 | my ($y_high, $y_low, $y_close) = @$y_point; | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 1108 | my ($PDM, $MDM) = (0,0); | |||||||||||||||||||||||||||||||
| 62 | 1108 | my $A = $t_high - $y_high; | |||||||||||||||||||||||||||||||
| 63 | 1108 | my $B = $y_low - $t_low; | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 1108 | ▶ | if( $A > 0 and $A > $B ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$A > 0 and $A > $B
MC/DC100%2/2
$A > 0 and $A > $B
$A > 0
$A > $B
Truth table100%3/3
A and B
A= $A > 0B= $A > $B
| |||||||||||||||||||||||||||||||||
| 66 | 468 | $PDM = $A; | |||||||||||||||||||||||||||||||
| 67 | 468 | $MDM = 0; | |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | ▶ | } elsif( $B > 0 and $B > $A ) { | |||||||||||||||||||||||||||||||
|
Condition66%2/3
$B > 0 and $B > $A
MC/DC50%1/2
$B > 0 and $B > $A
$B > 0
$B > $A
Truth table66%2/3
A and B
A= $B > 0B= $B > $A
| |||||||||||||||||||||||||||||||||
| 70 | 412 | $PDM = 0; | |||||||||||||||||||||||||||||||
| 71 | 412 | $MDM = $B; | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 1108 | ▶ | if( defined(my $pdm = $this->{aPDM}) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | 1063 | my $mdm = $this->{aMDM}; | |||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 1063 | my $R = $this->{R}; | |||||||||||||||||||||||||||||||
| 78 | 1063 | my $R1 = $this->{R1}; | |||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 1063 | my $aPDM = $this->{aPDM} = $R * $pdm + $R1 * $PDM; | |||||||||||||||||||||||||||||||
| 81 | 1063 | my $aMDM = $this->{aMDM} = $R * $mdm + $R1 * $MDM; | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 1063 | my $ATR = $atr->query; | |||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 1063 | ▶ | if( $ATR == 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 86 | 0 | my $DX = $this->{PDI} = $this->{MDI} = 0; | |||||||||||||||||||||||||||||||
| 87 | 0 | $this->{ADX} = $R * $this->{ADX} + $R1 * $DX; | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||||||||
| 90 | 1063 | my $PDI = $this->{PDI} = $aPDM / $ATR; | |||||||||||||||||||||||||||||||
| 91 | 1063 | my $MDI = $this->{MDI} = $aMDM / $ATR; | |||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 1063 | my $DI = abs( $PDI - $MDI ); | |||||||||||||||||||||||||||||||
| 94 | 1063 | ▶ | my $DX = $DI ? $DI / ($PDI + $MDI) : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 95 | # 0/0 is indeterminent form, but I think 0 makes sense | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 1063 | $this->{ADX} = $R * $this->{ADX} + $R1 * $DX; | |||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||||||
| 101 | 45 | my $p; | |||||||||||||||||||||||||||||||
| 102 | 45 | my $N = $this->{days}; | |||||||||||||||||||||||||||||||
| 103 | 45 | ▶ | if( ref($p = $this->{_p}) and (@$p >= $N-1) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref($p = $this->{"_p"}) and @$p >= $N - 1
MC/DC100%2/2
ref($p = $this->{"_p"}) and @$p >= $N - 1
ref($p = $this->{"_p"})
@$p >= $N - 1
Truth table100%3/3
A and B
A= ref($p = $this->{"_p"})B= @$p >= $N - 1
| |||||||||||||||||||||||||||||||||
| 104 | 3 | my $psum = 0; | |||||||||||||||||||||||||||||||
| 105 | 3 | $psum += $_ for @$p; | |||||||||||||||||||||||||||||||
| 106 | 3 | $psum += $PDM; | |||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 3 | my $m = $this->{_m}; | |||||||||||||||||||||||||||||||
| 109 | 3 | my $msum = 0; | |||||||||||||||||||||||||||||||
| 110 | 3 | $msum += $_ for @$m; | |||||||||||||||||||||||||||||||
| 111 | 3 | $msum += $MDM; | |||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 3 | my $aPDM = $this->{aPDM} = $psum / $N; | |||||||||||||||||||||||||||||||
| 114 | 3 | my $aMDM = $this->{aMDM} = $msum / $N; | |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 3 | my $ATR = $atr->query; | |||||||||||||||||||||||||||||||
| 117 | 3 | ▶ | if( $ATR == 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | 0 | $this->{PDI} = $this->{MDI} = $this->{ADX} = 0; | |||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | } else { | ||||||||||||||||||||||||||||||||
| 121 | 3 | my $PDI = $this->{PDI} = $aPDM / $ATR; | |||||||||||||||||||||||||||||||
| 122 | 3 | my $MDI = $this->{MDI} = $aMDM / $ATR; | |||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 3 | my $DI = abs( $PDI - $MDI ); | |||||||||||||||||||||||||||||||
| 125 | 3 | ▶ | my $DX = $DI ? $DI / ($PDI + $MDI) : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 126 | # 0/0 is indeterminent form, but I think 0 makes sense | ||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | 3 | $this->{ADX} = $DX; # is this right? No idea... I assume this is well documented in his book | |||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 3 | delete $this->{_p}; | |||||||||||||||||||||||||||||||
| 132 | 3 | delete $this->{_m}; | |||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | } else { | ||||||||||||||||||||||||||||||||
| 135 | 42 | push @{$this->{_p}}, $PDM; | |||||||||||||||||||||||||||||||
| 136 | 42 | push @{$this->{_m}}, $MDM; | |||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 1112 | $y_point = $point; | |||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 1109 | $this->{y} = $y_point; | |||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub query_pdi { my $this = shift; return $this->{PDI}; } | ||||||||||||||||||||||||||||||
|
Subroutine
query_pdi: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub query_mdi { my $this = shift; return $this->{MDI}; } | ||||||||||||||||||||||||||||||
|
Subroutine
query_mdi: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | sub query { | ||||||||||||||||||||||||||||||||
| 151 | 2017 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
query: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | 2017 | ▶ | return ($this->{PDI}, $this->{MDI}, $this->{ADX}) if wantarray; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 154 | 1009 | return $this->{ADX}; | |||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||||||