Time series (stock data), how to know which price level was hit first in intraday data

11 次查看(过去 30 天)
I have a time seriers (stock prices)
It's intraday data, 10 mins bars, so this mean each row of data that has open,high,low,close, time data is for 10mins (not a full day).
I want to be able to identify starting from 9:30AM, does price move up 30 pips (points) before it moves down 50 points.
So for example, for forex data EURUSD instrument.
At 9:30AM the price can be 1.06840, then by the close of the day the price can be 1.06940, so price went up, but between the start and end of the day there could be a million possibilities on how it got there.
So i need to know if my stop got hit first or if my target got hit first.
It could have gone up 30 pips, and then down 50 pips, and then back up 100pips.
In a timetable, where we have time, open, high, low, close.
how can I know which if the close first hit a level of 1.06870 first, or did it hit 1.06810.
How do i know number showed up first within a table?

回答(1 个)

Tejas
Tejas 2024-11-11,7:58
Hello Rizwan,
It seems the question is about determining whether the price increased by 30 pips first or decreased by 50 pips first after opening at 9:30 AM.
Assuming the data is stored in a table with the first row containing column names, follow these steps to identify whether the target or stop was hit first:
  • Define the target and stop levels.
starting_price = data.Open(1);
target_level = starting_price + 0.00030; % 30 pips up
stop_level = starting_price - 0.00050; % 50 pips down
  • Declare flags to record which level was hit first.
target_hit = false;
stop_hit = false;
hit_time = NaT;
  • Iterate over each row, updating the flag when the target or stop level is hit, and store the hit time in a variable named 'hit_time'.
for i = 2:height(data)
if data.High(i) >= target_level && ~target_hit
target_hit = true;
hit_time = data.Time(i);
end
if data.Low(i) <= stop_level && ~stop_hit
stop_hit = true;
hit_time = data.Time(i);
end
end
  • Use the code snippet below to display the results:
if target_hit && ~stop_hit
fprintf('Target level was hit first at %s.\n', char(hit_time));
elseif stop_hit && ~target_hit
fprintf('Stop level was hit first at %s.\n', char(hit_time));
else
fprintf('Neither level was hit by the end of the day.\n');
end

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by