How can I plot the candle line into two figures with one time series object?

1 vue (au cours des 30 derniers jours)
Candace Chou
Candace Chou le 15 Mai 2016
Réponse apportée : BhaTTa le 12 Sep 2024
Hello everyone, I am now doing a project about the stock .And now I need to plot a candle line, I plotted it successesfully,However ,because I have about 300 days to plot into one figure,It is too small to regonize the details.I am know wondering if I can plot two figures with successive time, ex:the time of first figure is from 01/01 ~05/03 ,and the other one is from 05/03~07/07 but I have no idea how to do it? any idea? My candle code is simple :candle(DATA(:,2),DATA(:,3),DATA(:,4),DATA(:,1),'b')

Réponses (1)

BhaTTa
BhaTTa le 12 Sep 2024
@Candace Chou, to handle the issue of plotting a large number of data points in a candlestick chart, you can split your data into multiple segments and plot them in separate figures. This will allow you to focus on smaller time intervals, making it easier to analyze the details.
Here's how you can achieve this in MATLAB:
Step-by-Step Guide
  1. Load Your Data: Ensure your data is properly loaded. It seems you have a matrix DATA where each row corresponds to a day, and columns represent Open, High, Low, and Close prices.
  2. Determine the Split Points: Decide how you want to split your data. For example, you might want to split it into two parts as you mentioned.
  3. Plot the Data in Segments: Use the candle function to plot each segment separately.
Here's an example of how you could implement this:
% Set random seed for reproducibility
rng(0);
% Generate dummy data for 300 days
numDays = 300;
openPrices = 100 + cumsum(randn(numDays, 1)); % Start around 100 and add random walk
highPrices = openPrices + abs(randn(numDays, 1)); % High is always higher than open
lowPrices = openPrices - abs(randn(numDays, 1)); % Low is always lower than open
closePrices = lowPrices + abs(randn(numDays, 1)); % Close is between low and high
% Combine into a matrix
DATA = [openPrices, highPrices, lowPrices, closePrices];
% Define the indices for splitting the data
splitIndex1 = 1; % Start of the first segment
splitIndex2 = 150; % End of the first segment/start of the second segment
splitIndex3 = numDays; % End of the second segment
% Plot the first segment
figure;
candle(DATA(splitIndex1:splitIndex2, 1), DATA(splitIndex1:splitIndex2, 2), ...
DATA(splitIndex1:splitIndex2, 3), DATA(splitIndex1:splitIndex2, 4), 'b');
title('Candlestick Chart: Segment 1');
xlabel('Days');
ylabel('Price');
% Plot the second segment
figure;
candle(DATA(splitIndex2+1:splitIndex3, 1), DATA(splitIndex2+1:splitIndex3, 2), ...
DATA(splitIndex2+1:splitIndex3, 3), DATA(splitIndex2+1:splitIndex3, 4), 'b');
title('Candlestick Chart: Segment 2');
xlabel('Days');
ylabel('Price');

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by