GeniusTrader/Indicators/FromTimeframe.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 66 CC 3 SCAR 15.0
CC
3
Cov
0%
calculate
12.0
initialize
2.0
BEGIN
2.0
CRAP 4.5
1 package Finance::GeniusTrader::Indicators::FromTimeframe;
2  
3 # Copyright 2004 Oliver Bossert
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::Prices;
14 use Finance::GeniusTrader::Eval;
15 use Finance::GeniusTrader::DateTime;
16 use Finance::GeniusTrader::Calculator;
17 use Finance::GeniusTrader::Tools qw(extract_object_number);
18  
19 @ISA = qw(Finance::GeniusTrader::Indicators);
20 @NAMES = ("FromTimeframe[#*]");
21 @DEFAULT_ARGS = ("{I:Prices CLOSE}", "week", 0);
22  
23 =head1 NAME
24  
25 Finance::GeniusTrader::Indicators::FromTimeframe - Get data from an other timeframe
26  
27 =head1 DESCRIPTION
28  
29 If you need data from an other timeframe (e.g. to determine the trend
30 on weekly basis), you can use this indicator.
31  
32 =head1 PARAMETERS
33  
34 =over
35  
36 =item Data
37  
38 A normal indicators-/data-object.
39  
40 =item Timeframe
41  
42 The timeframe you want to get
43  
44 =item Days
45  
46 The number of periods you want to go back in the requested timeframe.
47  
48 =back
49  
50 =cut
51 sub initialize {
52 my $self = shift;
53 }
54  
55 sub calculate {
56 my ($self, $calc, $i) = @_;
57 my $code = $calc->{'code'};
58 my $indic = $calc->indicators;
59 my $nb = $self->{'args'}->get_arg_values($calc, $i, 3);
60  
61 # Initialize
62 if (!defined($self->{$code}->{'special_calc'})) {
63 $self->{$code}->{'special_tf'} = Finance::GeniusTrader::DateTime::name_to_timeframe($self->{'args'}->get_arg_constant(2));
64 $self->{$code}->{'special_prices'} = $calc->prices->convert_to_timeframe($self->{$code}->{'special_tf'});
65 $self->{$code}->{'special_calc'} = Finance::GeniusTrader::Calculator->new($self->{$code}->{'special_prices'});
66 $self->{$code}->{'special_calc'}->set_code($calc->code());
67 } else {
68 }
69  
70  
71 my $date = $calc->prices->at($i)->[$DATE];
72 my $time = Finance::GeniusTrader::DateTime::map_date_to_time($calc->prices->timeframe(), $date);
73 $date = Finance::GeniusTrader::DateTime::map_time_to_date($self->{$code}->{'special_tf'}, $time);
74  
75 if ($self->{$code}->{'special_prices'}->has_date($date)) {
76 my $j = $self->{$code}->{'special_prices'}->date($date);
77 my $tmp = $self->{'args'}->get_arg_names(1);
78 $tmp =~ s/^{|}$//g;
79  
80 my $args = Finance::GeniusTrader::ArgsTree->new( $tmp );
81 my $name_index = extract_object_number($args->get_arg_names(1));
82 my $ob = $self->{'args'}->get_arg_object(1);
83 $ob->calculate($self->{$code}->{'special_calc'}, $j - $nb);
84 my $res = $self->{$code}->{'special_calc'}->indicators->get($ob->get_name($name_index), $j - $nb);
85 $indic->set($self->get_name, $i, $res);
86 }
87  
88 }
89  
90 1;