Find all records where the min low price occurs before the max high price, in terms of datetime

Viewed 31

I have a table of candle stick data for 26 stocks A to Z. A 1-minute candlestick is a visualization of stock trading prices for a 1-minute period showing the below:

  • ticker: the letter representing a stock, from A to Z.
  • open_price: price of stock at the start of the period
  • close_price: price of stock at the end of the period
  • high: highest price in the period
  • low: lowest price in the period
  • date_time: date and time of the observation. (Every new date_time data is increments of 1 min. When I created my table, I have put this data type as TIMESTAMP, in order to calculate the difference with greater convenience).

The above fields are also the columns of the table, and there are 1M records in total, so each ticker has about 38K+ of records.

My table:

create table stock_price
(   ticker char(1),
    candle char(5),
    date_time timestamp,
    open_price decimal (10,4),
    close_price decimal (10,4),
    high decimal (10,4),
    low decimal (10,4),
    volume bigint unsigned);

I'm stuck at the following questions:

  1. Find all tickers where the minimum low occurs before the max high, in terms of date_time
  2. For each ticker, find the candlestick combination where the date_time difference between the minimum low and maximum high is the shortest

NOTE: Keep in mind there could be multiple min low and max high prices per ticker. You need to find the min Low and max High candlesticks that are chronologically closest to each other.

I'm using MySQL Workbench 8.0.

I'm sorry I cannot upload a picture of my table as I don't have enough points, and when I try to type out my table here, there's not enough space. I also apologise if my question is not of the right formatting or cannot be more succinct, as I'm new to programming.

Thank you community so much in advance!

0 Answers
Related