]> Creatis software - CreaPhase.git/blob - octave_packages/financial-0.4.0/highlow.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / financial-0.4.0 / highlow.m
1 ## Copyright (C) 2008 Bill Denney <bill@denney.ws>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {@var{h} =} highlow (@var{high}, @var{low}, @var{close})
18 ## @deftypefnx {Function File} {@var{h} =} highlow (@var{high}, @var{low}, @var{close}, @var{open})
19 ## @deftypefnx {Function File} {@var{h} =} highlow (@var{high}, @var{low}, @var{close}, @var{open}, @var{color})
20 ##
21 ## Plot the @var{high}, @var{low}, and @var{close} of a security.  The
22 ## @var{close} is plotted as a tick to the right, and if @var{open} is
23 ## given and non-empty, it is plotted as a tick to the left.  The color
24 ## can override the default color for the plot.
25 ##
26 ## @seealso{bolling, candle, dateaxis, movavg, pointfig}
27 ## @end deftypefn
28
29 function h = highlow (high, low, close, open = [], color)
30
31   if nargin < 3 || nargin > 5
32     print_usage ();
33   elseif nargin < 5
34     plotargs = {};
35   else
36     plotargs = {"color", color};
37   endif
38
39   if isempty (high) || isempty (low) || isempty (close)
40     error ("high, low, and close may not be empty")
41   elseif ~(isvector (high) && isvector (low) && isvector (close))
42     error ("high, low, and close must be vectors")
43   elseif ( (numel (high) != numel (low)) || (numel (high) != numel (close)) )
44     error ("high, low, and close must have the same number of elements")
45   elseif ( !isempty (open) && (numel (high) != numel (open)) )
46     error ("open must have the same number of elements as high, low, and close")
47   endif
48
49   holdstat = ishold ();
50   ## h = hggroup ();
51   ## plotargs(end+1:end+2) = {"parent", h};
52   hold on;
53   x = (1:length(high)) + 0.5;
54   x = reshape([x;x;nan(size(x))], [], 1);
55   y = reshape([high(:)'; low(:)'; nan(1, length(high))], [], 1);
56   plot(x, y, plotargs{:});
57   x = 1:length(high);
58   x = reshape([x+0.5;x+1;nan(size(x))], [], 1);
59   y = reshape([close(:)';close(:)';nan(1, length(close))], [], 1);
60   plot(x, y, plotargs{:});
61   if ! isempty(open)
62     x -= 0.5;
63     y = reshape([open(:)';open(:)';nan(1, length(open))], [], 1);
64     plot(x, y, plotargs{:});
65   endif
66
67   if !holdstat
68     hold off;
69   endif
70
71 endfunction