GeniusTrader/Indicators/TETHER.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 61 CC 3 SCAR 16.1
CC
3
Cov
0%
calculate
12.0
initialize
2.0
BEGIN
2.0
CRAP 5.0
1 package Finance::GeniusTrader::Indicators::TETHER;
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::Generic::MinInPeriod;
14 use Finance::GeniusTrader::Indicators::Generic::MaxInPeriod;
15 use Finance::GeniusTrader::Prices;
16  
17 @ISA = qw(Finance::GeniusTrader::Indicators);
18 @NAMES = ("TETHER[#1]");
19 @DEFAULT_ARGS = (50);
20  
21 =head1 NAME
22  
23 Finance::GeniusTrader::Indicators::TETHER - Tether Line
24  
25 =head1 DESCRIPTION
26  
27 The Tether Line is one of the three indicators used in Trend Following System (TFS), designed by Bryan Strain.
28  
29 =head1 CALCULATION
30  
31 Tether Line = (Highest High (n) + Lowest Low (n)) / 2
32  
33 =head1 PARAMETERS
34  
35 The standard Tether Line works with a 50-day parameter : n = 50
36  
37 =head1 EXAMPLE
38  
39 Finance::GeniusTrader::Indicators::TETHER->new()
40 Finance::GeniusTrader::Indicators::TETHER->new([30])
41  
42 =cut
43 sub initialize {
44 my $self = shift;
45  
46 $self->{'min'} = Finance::GeniusTrader::Indicators::Generic::MinInPeriod->new([ $self->{'args'}->get_arg_names(1), "{I:Prices LOW}" ]);
47 $self->{'max'} = Finance::GeniusTrader::Indicators::Generic::MaxInPeriod->new([ $self->{'args'}->get_arg_names(1), "{I:Prices HIGH}" ]);
48  
49 $self->add_indicator_dependency($self->{'min'}, 1);
50 $self->add_indicator_dependency($self->{'max'}, 1);
51 $self->add_prices_dependency($self->{'args'}->get_arg_constant(1));
52 }
53  
54 =head2 Finance::GeniusTrader::Indicators::TETHER::calculate($calc, $day)
55  
56 =cut
57 sub calculate {
58 my ($self, $calc, $i) = @_;
59 my $indic = $calc->indicators;
60 my $q = $calc->prices;
61 my $period = $self->{'args'}->get_arg_values($calc, $i, 1);
62 my $min = $self->{'min'};
63 my $max = $self->{'max'};
64 my $min_name = $min->get_name;
65 my $max_name = $max->get_name;
66 my $tether_name = $self->get_name(0);
67  
68 return if ($indic->is_available($tether_name, $i));
69 return if (! $self->check_dependencies($calc, $i));
70  
71 # Get MIN and MAX values
72 my $min_value = $indic->get($min_name, $i);
73 my $max_value = $indic->get($max_name, $i);
74  
75 # The tether line is equal to the sum of the highest high and lowest low, divided by two
76 my $tether_line_value = (($min_value + $max_value) / 2);
77
78 # Return the result
79 $indic->set($tether_name, $i, $tether_line_value);
80 }
81  
82 1;