- 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.
- 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.
- Plot the Data in Segments: Use the candle function to plot each segment separately.
How can I plot the candle line into two figures with one time series object?
1 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
回答(1 个)
BhaTTa
2024-9-12
@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
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');
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!