GeniusTrader/Graphics/Object/CandleVolumePlace.pm untested

filter: Statementstmt 0.0% 0 / 78 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 107 CC 10 SCAR 41.3
CC
10
Cov
0%
display
110.0
init
2.0
BEGIN
2.0
CRAP 62.0
1 package Finance::GeniusTrader::Graphics::Object::CandleVolumePlace;
2  
3 # Copyright 2003 Oliver Bossert
4 # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber
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 # $Id$
9  
10 use strict;
11 use vars qw(@ISA);
12 @ISA = qw(Finance::GeniusTrader::Graphics::Object);
13  
14 use Finance::GeniusTrader::Prices;
15 use Finance::GeniusTrader::Graphics::Object;
16 use Finance::GeniusTrader::Graphics::Driver;
17 use Finance::GeniusTrader::Graphics::Tools qw(:color);
18 use Finance::GeniusTrader::Conf;
19  
20 Finance::GeniusTrader::Conf::default("Graphic::Candle::UpColor", "green");
21 Finance::GeniusTrader::Conf::default("Graphic::Candle::DownColor", "red");
22 Finance::GeniusTrader::Conf::default("Graphic::Candle::Width", 6);
23  
24 =head1 Finance::GeniusTrader::Graphics::Object::CandleVolumePlace
25  
26 This graphical object display a series of candlesticks.
27 The width of each candle is determined by the volume.
28  
29 =cut
30  
31 sub init {
32 my ($self) = @_;
33
34 # Default values ...
35 $self->{'up_body_color'} =
36 get_color(Finance::GeniusTrader::Conf::get("Graphic::Candle::UpColor"));
37 $self->{'up_body_border_color'} =
38 get_color(Finance::GeniusTrader::Conf::get_first(
39 "Graphic::Candle::UpBorderColor",
40 "Graphic::Candle::BorderColor",
41 "Graphic::ForegroundColor"
42 ));
43 $self->{'up_shadows_color'} =
44 get_color(Finance::GeniusTrader::Conf::get_first(
45 "Graphic::Candle::UpShadowColor",
46 "Graphic::Candle::ShadowColor",
47 "Graphic::Candle::UpBorderColor",
48 "Graphic::Candle::BorderColor",
49 "Graphic::ForegroundColor"
50 ));
51
52 $self->{'down_body_color'} =
53 get_color(Finance::GeniusTrader::Conf::get("Graphic::Candle::DownColor"));
54 $self->{'down_body_border_color'} =
55 get_color(Finance::GeniusTrader::Conf::get_first(
56 "Graphic::Candle::DownBorderColor",
57 "Graphic::Candle::BorderColor",
58 "Graphic::ForegroundColor"
59 ));
60 $self->{'down_shadows_color'} =
61 get_color(Finance::GeniusTrader::Conf::get_first(
62 "Graphic::Candle::DowbShadowColor",
63 "Graphic::Candle::ShadowColor",
64 "Graphic::Candle::DownBorderColor",
65 "Graphic::Candle::BorderColor",
66 "Graphic::ForegroundColor"
67 ));
68
69 $self->{'width'} = Finance::GeniusTrader::Conf::get("Graphic::Candle::Width");
70 }
71  
72 sub display {
73 my ($self, $driver, $picture) = @_;
74 my $scale = $self->get_scale();
75 my $zone = $self->{'zone'};
76 my $width = $self->{'width'};
77 my ($start, $end) = $self->{'source'}->get_selected_range();
78  
79 # only $y_min and $y_max are significant
80 my ($x_min, $y_min) = $scale->get_value_from_coordinate($start, 0);
81 my ($x_max, $y_max) = $scale->get_value_from_coordinate($end, $zone->height-1);
82  
83 # these are coordinate values of $y_min and $y_max
84 my $yc_min = $scale->convert_to_y_coordinate($y_min);
85 my $yc_max = $scale->convert_to_y_coordinate($y_max);
86  
87 my $holevolume = 0;
88 for(my $i = $start; $i <= $end; $i++)
89 {
90 my $data = $self->{'source'}->get($i);
91 $holevolume += $data->[$VOLUME];
92 }
93 my $holewidth = $scale->convert_to_x_coordinate($end)-
94 $scale->convert_to_x_coordinate($start) + $self->{'width'};
95  
96 for(my $i = $start; $i <= $end; $i++)
97 {
98 my $data = $self->{'source'}->get($i);
99 my $low = $scale->convert_to_y_coordinate($data->[$LOW]);
100 my $open = $scale->convert_to_y_coordinate($data->[$OPEN]);
101 my $close = $scale->convert_to_y_coordinate($data->[$CLOSE]);
102 my $high = $scale->convert_to_y_coordinate($data->[$HIGH]);
103 $self->{'width'} = $holewidth * $data->[$VOLUME] / $holevolume;
104 my $x = $scale->convert_to_x_coordinate($i);
105  
106 # clip $y at top of zone
107 $low = $yc_max if ( $low > $yc_max );
108 $open = $yc_max if ( $open > $yc_max );
109 $close = $yc_max if ( $close > $yc_max );
110 $high = $yc_max if ( $high > $yc_max );
111 # clip $y at bottom of zone
112 $low = $yc_min if ( $low < $yc_min );
113 $open = $yc_min if ( $open < $yc_min );
114 $close = $yc_min if ( $close < $yc_min );
115 $high = $yc_min if ( $high < $yc_min );
116  
117 if ($data->[$OPEN] < $data->[$CLOSE]) {
118
119 $driver->filled_rectangle($picture,
120 $zone->absolute_coordinate($x + 1, $open + 1),
121 $zone->absolute_coordinate($x + $self->{'width'} - 2 - 1, $close - 1),
122 $self->{'up_body_color'});
123  
124 $driver->rectangle($picture,
125 $zone->absolute_coordinate($x, $open),
126 $zone->absolute_coordinate($x + $self->{'width'} - 2, $close),
127 $self->{'up_body_border_color'});
128
129 $driver->line($picture,
130 $zone->absolute_coordinate($x + int($self->{'width'} / 2) - 1, $close + 1),
131 $zone->absolute_coordinate($x + int($self->{'width'} / 2) - 1, $high), $self->{'up_shadows_color'});
132
133 $driver->line($picture,
134 $zone->absolute_coordinate($x + int($self->{'width'} / 2) - 1, $low),
135 $zone->absolute_coordinate($x + int($self->{'width'} / 2) - 1, $open - 1), $self->{'up_shadows_color'});
136  
137 } else {
138
139 $driver->filled_rectangle($picture,
140 $zone->absolute_coordinate($x + 1, $close + 1),
141 $zone->absolute_coordinate($x + $self->{'width'} - 2 - 1, $open - 1), $self->{'down_body_color'});
142  
143 $driver->rectangle($picture,
144 $zone->absolute_coordinate($x, $close),
145 $zone->absolute_coordinate($x + $self->{'width'} - 2, $open), $self->{'down_body_border_color'});
146  
147 $driver->line($picture,
148 $zone->absolute_coordinate($x + int($self->{'width'} / 2) - 1, $open + 1),
149 $zone->absolute_coordinate($x + int($self->{'width'} / 2) - 1, $high), $self->{'down_shadows_color'});
150
151 $driver->line($picture,
152 $zone->absolute_coordinate($x + int($self->{'width'} / 2) - 1, $low),
153 $zone->absolute_coordinate($x + int($self->{'width'} / 2) - 1, $close - 1), $self->{'down_shadows_color'});
154 }
155 }
156 }
157  
158 1;