GeniusTrader/Indicators/DSS.pm untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 96 CC 6 SCAR 18.8
CC
6
Cov
0%
calculate
12.0
calculate_interval
12.0
initialize
6.0
CRAP 6.5
1 package Finance::GeniusTrader::Indicators::DSS;
2  
3 # Copyright 2002 Oliver Bossert
4 # Updated 2006, 2008 by Karsten Wippler, Thomas Weigert
5 # This file is distributed under the terms of the General Public License
6 # version 2 or (at your option) any later version.
7  
8 # Standards-Version: 1.0
9  
10 use strict;
11 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
12  
13 use Finance::GeniusTrader::ArgsTree;
14 use Finance::GeniusTrader::Indicators;
15 use Finance::GeniusTrader::Indicators::EMA;
16 use Finance::GeniusTrader::Indicators::Generic::MinInPeriod;
17 use Finance::GeniusTrader::Indicators::Generic::MaxInPeriod;
18  
19 @ISA = qw(Finance::GeniusTrader::Indicators);
20 @NAMES = ("DSS-BLAU[#1,#2,#3]");
21 @DEFAULT_ARGS = (5,7,3,"{I:Prices HIGH}","{I:Prices LOW}","{I:Prices CLOSE}");
22  
23 =head1 NAME
24  
25 Finance::GeniusTrader::Indicators::DSS - Double Smoothed Stochastic (William Blau).
26  
27  
28 =head1 DESCRIPTION
29  
30 From http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=128:
31  
32 DSS applies 2 smoothing EMAs of different lengths to a Stochastic Oscillator.
33 DSS ranges from 0 to 100, like the standard Stochastic Oscillator. The same
34 rules of interpretation that you use for Stochastics can be applied to DSS,
35 although DSS offers a much smoother curve than Stochastics.
36  
37 From http://www.tradesignalonline.com/Lexicon/Default.aspx?name=DSS%3a+Double+Smoothed+Stochastics+(Blau)
38  
39 Calculation of the DSS indicator is similar to stochastics. The numerator:
40 first the difference between the current close and the period low is formed,
41 and this is then exponentially smoothed twice. The denominator is formed in
42 the same way, but here the difference is calculated from the period high minus
43 the period low. Numerator and denominator yield the quotient, and this value
44 is multiplied by 100.
45  
46 =head2 Calculation
47  
48 As can be seen from above, there is some disagreement on the calculation
49 process. We follow the latter and calculate DSS-BLAU as follows:
50  
51 DSS-BLAU[p1,p2,p3] =
52 EMA[p3, EMA[p2, Close - LowestLow[p1]]
53 100 * ----------------------------------------------
54 EMA[p3, EMA[p2, HighestHigh[p1]-LowestLow[p1]]
55  
56 The handling and the calculations of signals is similar to the
57 Stochastic-Indictor.
58  
59 =head2 Parameters
60  
61 =over
62  
63 =item Period 1 (default 5)
64  
65 The period over which to consider highest highs and lowest lows.
66  
67 =item Period 2 (default 7)
68  
69 The period of the first smoothing
70  
71 =item Period 3 (default 3)
72  
73 The period of the second smoothing
74  
75 =item High, Low, and Close of Source
76  
77 The source from which the indicators is calculated.
78  
79 =back
80  
81 =cut
82  
83  
84 sub initialize {
85 my ($self) = @_;
86 my $args = $self->{'args'};
87  
88 for (my $i=1;$i<=3;$i++) {
89 die "Argument $i to ".$self->get_name." must be a constant value.\n" unless $args->is_constant($i);
90 }
91  
92 my $nb1 = $args->get_arg_names(1);
93 my $nb2 = $args->get_arg_names(2);
94 my $nb3 = $args->get_arg_names(3);
95  
96 my $min = "{I:Generic:Eval ".$args->get_arg_names(6)." - {I:Generic:MinInPeriod $nb1 ".$args->get_arg_names(5)."}}";
97 my $max = "{I:Generic:Eval {I:Generic:MaxInPeriod $nb1 ".$args->get_arg_names(4)."} - {I:Generic:MinInPeriod $nb1 ".$args->get_arg_names(5)."}}";
98  
99 $self->{'num'} = Finance::GeniusTrader::Indicators::EMA->new([$nb3, "{I:EMA $nb2 $min}"]);
100 $self->{'den'} = Finance::GeniusTrader::Indicators::EMA->new([$nb3, "{I:EMA $nb2 $max}"]);
101  
102 $self->add_prices_dependency( $nb1 + $nb2 + $nb3 );
103 $self->add_indicator_dependency( $self->{'num'}, 1 );
104 $self->add_indicator_dependency( $self->{'den'}, 1 );
105  
106 }
107  
108 sub calculate {
109 my ($self, $calc, $i) = @_;
110 my $indic = $calc->indicators;
111 my $name = $self->get_name();
112  
113 return if ($calc->indicators->is_available($name, $i));
114 return if (! $self->check_dependencies($calc, $i));
115  
116 my $den = $indic->get($self->{'den'}->get_name, $i) || 0.0000001;
117 my $dss = 100 * $indic->get($self->{'num'}->get_name, $i) / $den;
118 $indic->set($name, $i, $dss);
119 }
120  
121 sub calculate_interval {
122 my ($self, $calc, $first, $last) = @_;
123 my $indic = $calc->indicators;
124 my $name = $self->get_name();
125  
126 return if ($calc->indicators->is_available_interval($name, $first, $last));
127 while (! $self->check_dependencies_interval($calc, $first, $last)) {
128 return if $first == $last;
129 $first++;
130 }
131  
132 for(my $i = $first; $i <= $last; $i++) {
133 my $den = $indic->get($self->{'den'}->get_name, $i) || 0.0000001;
134 my $dss = 100 * $indic->get($self->{'num'}->get_name, $i) / $den;
135 $indic->set($name, $i, $dss);
136 }
137 }
138  
139 1;