don't color body

조회 수: 43 (최근 30일)
shamal
shamal 2025년 9월 1일 17:04
댓글: shamal 2025년 9월 1일 18:55
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
dpb
dpb 2025년 9월 1일 18:43
And then tell us explicitly what is/isn't what you were expecting/wanting.
shamal
shamal 2025년 9월 1일 18:55
problem solved...if I enlarge the graph I see the colors

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by