GeniusTrader/Indicators/QSTICK.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 46 CC 3 SCAR 16.7
CC
3
Cov
0%
calculate
12.0
initialize
2.0
BEGIN
2.0
CRAP 5.3
1 package Finance::GeniusTrader::Indicators::QSTICK;
2  
3 # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber
4 # This file is distributed under the terms of the General Public License
5 # version 2 or (at your option) any later version.
6  
7 # Standards-Version: 1.0
8  
9 use strict;
10 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
11  
12 use Finance::GeniusTrader::Indicators;
13 use Finance::GeniusTrader::Indicators::SMA;
14 use Finance::GeniusTrader::Prices;
15  
16 @ISA = qw(Finance::GeniusTrader::Indicators);
17 @NAMES = ("QSTICK[#*]");
18 @DEFAULT_ARGS = (10, "{I:Prices CLOSE}", "{I:Prices OPEN}");
19  
20 =head1 Finance::GeniusTrader::Indicators::QSTICK
21  
22 =head2 Overview
23  
24 The QStick indicator was designed by Tushar Chandle to quantify candelsticks.
25  
26 The distance between opening and closing prices, as known as the size of the candelstick's body, is the heart of candelsticks studies. The QStick indicator is a simple moving average of theses distances.
27  
28 =head2 Interpretation
29  
30 QStick values below zero show that there is a majority of black candelsticks, so that the stock is under pressure.
31 QStick values upper zero show that there is a majority of white candelsticks, so that the stock is going up.
32  
33 =head2 Note
34  
35 I don't really like the terms 'majority of black candelsticks' and 'majority of white candelsticks', i prefer to talk about 'negative volatility' and 'positive volatility'. Moreover, it might be more usefull to calculate the QStick with the percentage deviation corrected by the standard deviation instead of the absolute deviation, in order to compares qstick values or to think about levels crossover.
36  
37 =head2 Calculation
38  
39 QStick Indicator = A-day simple moving average (SMA) of (Close - Open)
40  
41 =head2 Examples
42  
43 Finance::GeniusTrader::Indicators::QSTICK->new()
44 Finance::GeniusTrader::Indicators::QSTICK->new([20])
45  
46 =head2 Links
47  
48 http://www.metastock.fr/QSTICK.htm
49  
50 =cut
51  
52 sub initialize {
53 my $self = shift;
54
55 my $eval = "{I:Generic:Eval " . $self->{'args'}->get_arg_names(2) . " - " .
56 $self->{'args'}->get_arg_names(3) . "}";
57  
58 # Initialize the simple moving average (SMA) of (Close - Open)
59 $self->{'qstick'} = Finance::GeniusTrader::Indicators::SMA->new( [$self->{'args'}->get_arg_names(1), $eval] );
60  
61 $self->add_indicator_dependency($self->{'qstick'}, 1);
62 }
63  
64 =head2 Finance::GeniusTrader::Indicators::QSTICK::calculate($calc, $day)
65  
66 =cut
67 sub calculate {
68 my ($self, $calc, $i) = @_;
69 my $indic = $calc->indicators;
70 my $qstick_name = $self->{'qstick'}->get_name;
71 my $qstick_indicator_name = $self->get_name(0);
72 my $period = $self->{'args'}->get_arg_values($calc, $i, 1);
73
74 return if ($indic->is_available($qstick_indicator_name, $i));
75 return if (! $self->check_dependencies($calc, $i));
76  
77 # Get QStick value
78 my $qstick_value = $indic->get($qstick_name, $i);
79
80 # Return the results
81 $indic->set($qstick_indicator_name, $i, $qstick_value);
82 }
83  
84 1;