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} {} pointfig (@var{asset})
19 ## Plot the point figure chart of an @var{asset}. Upward price
20 ## movements are plotted as Xs and downward movements are plotted as Os.
22 ## @seealso{bolling, candle, dateaxis, highlow, movavg}
25 function pointfig (asset)
31 upmask = asset(2:end) > asset(1:end-1);
32 # if the data is equal, it will not change the trend
33 equalmask = asset(2:end) == asset(1:end-1);
34 downmask = asset(2:end) < asset(1:end-1);
42 for i = 1:length (upmask)
43 if direction > 0 && (upmask(i) || equalmask(i))
44 ## moving in the same direction as previously: up
46 up(end+1,:) = [lx ly];
47 elseif direction < 0 && (downmask(i) || equalmask(i))
48 ## moving in the same direction as previously: down
50 down(end+1,:) = [lx ly];
52 ## moving in a different direction than previously
55 up(end+1,:) = [lx ly];
58 down(end+1,:) = [lx ly];
66 plot(up(:,1), up(:,2), "x", "color", [0 0 1]);
67 plot(down(:,1), down(:,2), "o", "color", [1 0 0]);
76 %! a = [1 2 3 2 4 2 1];
78 %! [s l] = movavg(a, 2, 4);
79 %! assert(s, [1 1.5 2.5 2.5 3 3 1.5])
80 %! assert(l, [1 1.5 2 2 2.75 2.75 2.25])
82 %! [s l] = movavg(a', 2, 4);
83 %! assert(s, [1;1.5;2.5;2.5;3;3;1.5])
84 %! assert(l, [1;1.5;2;2;2.75;2.75;2.25])
86 %! [s l] = movavg(a, 3, 4, 1);
87 %! assert(s, [3 4.8 7 7 9.5 8 5.5]./3, 10*eps)
88 %! assert(l, [1 11/7 20/9 2.2 3 2.7 2], 10*eps)