don't color body

4 views (last 30 days)
shamal
shamal on 1 Sep 2025
Commented: shamal on 1 Sep 2025
Hi, i used chat gpt to create this code..i want to plot candlestick (trading) but i can't to color body
function BIAS_plotLastCandles6_test(grouped, n, bodyWidth, ax)
% BIAS_plotLastCandles2 - ultime n candele con body verdi/rossi
%
% grouped : struct con campi Open, High, Low, Close, Time
% n : numero di candele da mostrare (dalle più recenti)
% bodyWidth : (opzionale) larghezza corpo candela (default = 0.6)
% ax : (opzionale) handle assi (es. app.UIAxes).
% Se omesso, crea nuova figura.
if nargin < 3 || isempty(bodyWidth), bodyWidth = 0.6; end
if nargin < 4 || isempty(ax)
f = figure('Renderer','opengl');
ax = axes('Parent', f);
end
hold(ax, 'on');
%%****************
f = figure('Renderer','opengl');
ax = axes('Parent',f); hold(ax,'on');
%%*********************
% --- estrazione ultime n righe
N = numel(grouped.Close);
n = min(n, N);
idx = N-n+1:N;
O = grouped.Open(idx);
H = grouped.High(idx);
L = grouped.Low(idx);
C = grouped.Close(idx);
T = grouped.Time(idx);
% spessore minimo per doji
rangeHL = max(H) - min(L);
minH = max(eps, rangeHL * 0.005);
% --- wick neri
for i = 1:n
line(ax, [i i], [L(i) H(i)], 'Color', 'k');
y0 = min(O(i), C(i));
y1 = max(O(i), C(i));
h = y1 - y0;
if h <= 0
h = minH;
y0 = y0 - h/2;
end
if C(i) >= O(i)
col = [0 1 0]; % verde pieno
else
col = [1 0 0]; % rosso pieno
end
patch(ax, ...
[i-bodyWidth/2 i+bodyWidth/2 i+bodyWidth/2 i-bodyWidth/2], ...
[y0 y0 y0+h y0+h], ...
col, 'EdgeColor','k');
end
% --- asse X con date leggibili
if n > 1
step = max(1, round(n/10));
xticks(ax, 1:step:n);
xticklabels(ax, cellstr(datestr(T(1:step:end))));
else
xticks(ax, 1);
xticklabels(ax, cellstr(datestr(T)));
end
xlabel(ax, 'Time'); ylabel(ax, 'Price');
title(ax, sprintf('Ultime %d sessioni', n));
box(ax, 'on'); grid(ax, 'on');
xlim(ax, [0, n+1]);
end
  3 Comments
dpb
dpb on 1 Sep 2025
And then tell us explicitly what is/isn't what you were expecting/wanting.
shamal
shamal on 1 Sep 2025
problem solved...if I enlarge the graph I see the colors

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2025a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!