1 ## Copyright (C) 2008 Bill Denney <bill@denney.ws>
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
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
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/>.
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})
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.
26 ## @seealso{bolling, candle, dateaxis, movavg, pointfig}
29 function h = highlow (high, low, close, open = [], color)
31 if nargin < 3 || nargin > 5
36 plotargs = {"color", color};
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")
51 ## plotargs(end+1:end+2) = {"parent", h};
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{:});
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{:});
63 y = reshape([open(:)';open(:)';nan(1, length(open))], [], 1);
64 plot(x, y, plotargs{:});