+ Reply to Thread
Results 1 to 25 of 25

Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

  1. #1
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Hello all, great forum here. I have found many solutions to minor excel/VBA issues over the last few years. But I've never been stumped until now.

    I have a several million lines of Forex data (not all in the same Workbook thankfully) in minute format and need to convert the minute data to 5 minute (or higher timeframes - up to Weekly). I found a converter that someone else has developed. It works in taking every five lines of minutes and combining into a single line of data but it doesn't respect the timestamps in the date column.

    I am a novice when it comes to VBA (I just keep staring at the code) so if someone can take a look at the code and fix it so the DateTime is in YYYY-MM-DD HH:MM so each row should have the beginning time of YYYY-MM-DD HH:00 and then YYYY-MM-DD HH:05. There are many missing minutes, especially at the beginning of my data so I do not expect or desire to have a row for every 5 minute period, just when there is actual data.

    I have attached the converter and some of my sample data for you to see. Thanks, in advance, for any and all help.

    Patrick
    Attached Files Attached Files

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Do you want the value at the beginning of each period, or the average value throughout the period?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    No, OHLC refers to market data: Open, High, Low and Close of a period.

    Open would be the first B column value. High would be the highest value of the 5 rows of column C, Low would be the lowest value of the five rows being combined of column D. And close would be the value of the final of the 5 rows in column E.

    With there being some rows missing from each five minute period there may not always be 5 rows to combine into a single five minute OHLC row. We also call these bars or candles because they display this data on price charts. Thanks.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    The data is pretty random as to capture frequency ...

    A
    1
    Date
    2
    Mon 2000-06-05 12:03
    3
    Thu 2000-06-08 12:58
    4
    Thu 2000-06-08 12:59
    5
    Mon 2000-06-12 14:00
    6
    Tue 2000-06-13 22:25
    7
    Tue 2000-06-13 22:26
    8
    Tue 2000-06-13 22:36
    9
    Fri 2000-06-16 19:06
    10
    Fri 2000-06-16 19:08
    11
    Fri 2000-06-16 19:25
    12
    Mon 2000-06-19 17:02
    13
    Mon 2000-06-19 17:03
    14
    Tue 2000-06-20 18:08
    15
    Tue 2000-06-27 14:38
    16
    Tue 2000-06-27 16:34
    17
    Tue 2000-06-27 20:49
    18
    Tue 2000-06-27 20:50
    19
    Tue 2000-06-27 20:51
    20
    Tue 2000-06-27 20:53
    21
    Tue 2000-06-27 20:54
    22
    Wed 2000-06-28 20:56
    23
    Wed 2000-06-28 20:57
    24
    Wed 2000-06-28 21:28

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Anyway, it seems straightforward - read in the data, bin by period (1 min, 5 min, 1 hour, 1 day, 1 week, ...), and find period open, high high, low low, and period close, and spit it out on another sheet.

  6. #6
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Yes, true. Trading in AUDUSD was sporatic back in 2000. These should just get their own 5 minute row unless there happens to be more rows in the same five minute period.

    The attached DataConverter.xls does work to combine every five rows into one with the open from the first row, the close from the last 5th row and the high and low from whichever row those are in. I does work, but it doesn't honor the time stamp and organize the start of the five minute row at the top of the hour and so on.

  7. #7
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Yes, straightforward except how does one modify the VBA in DataConverter.xls to get the date-time to start at the start of every hour and every 5 min period thereafter???

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    I think this does what you want.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Wow, this looks good. Thank you so much. P

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    You're welcome.

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Fixed a bug and a little cleanup.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    OK, what was the bug?

    OK, after looking at it, it does do what I want, however, I forgot to be specific. I was hoping you'd modify the file DataConverter I attached because it had a place to input the file name and worksheet and specify the number of minutes. I just realized you say you started the week on Monday when it should start on Sundays. I see the line dBeg = Int(dMin) - (Weekday(dMin) + 5) Mod 7 ' start weekly on Monday; but looking up the function shows if it is omitted it defaults to Sunday which for the Weekly is perfect. Do you concur?

    Now for the hard part. I needed 240 and 1440 minutes. Yes I know that is a day but that is how we do it with forex. It trades all night and starts on Sunday here at 17:00 EST (its Monday morning in Asia). I was able to add the 240 and 1440 to the Case and to the dropdown menu, but it would be best to get these rows to start at 17:00 eastern on Sundays and go from there. Any ideas?

  13. #13
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Thanks for adding the table. I clearly had a few bad data points.

  14. #14
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Here is my file

  15. #15
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Oops attachment too big
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    This attachment
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Yea, it looks like the sunday is missing on the weekly

  18. #18
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Pardon? What Sunday?

  19. #19
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Sorry, I have been swamped the last couple of days and not feeling well on top of it. I really appreciate your help.

    None the Sundays show up on the weekly worksheet.

    I have attached a couple of screenshots showing daily data on Sunday Sept 12th, 2004 and on the weekly screenshot it doesn't even have a Sept 12th. It just starts on the 13th.
    As do all the other weeks.

    This is because my data is Eastern US time (Sundays at 17:00 in NY are Monday mornings in Asia; which is when the trading starts each week).

    So the weekly and 240 min data should each start at 17:00 on Sundays NY time.

    Anyway, I hope all is well with you.

    PatrickA
    Attached Images Attached Images

  20. #20
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    I was thinking of a simple VBA that change all the source data by adding 16 hours to each date. But then I thought roll the Input data forward 16 hours (to Melborne time). Then create the output and roll the Output data back to NY time. Also, seems like the Input data should be rolled back to NY time to create a new Output and so all the series are synced. What do you think? it might be the easiest thing.

  21. #21
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Easiest would be to have your input data already converted to the time zone of interest.

    Second easiest would be an input cell containing an offset that gets added to every time value to convert your local times to the time zone of interest (which are the times that would display in the output range). An inconvenience is that the 1900 date system does not support display of negative times.

  22. #22
    Registered User
    Join Date
    01-17-2016
    Location
    Santa clara
    MS-Off Ver
    2010
    Posts
    14

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Yea, that is what I had to do. It works but is tedious to copy the date columns back and forth and then copy back into the Input sheet.

    BTW, your tool is quite fragile because of all the named spaces and the header. The code breaks if I don't copy by rows.

  23. #23
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    It works but is tedious to copy the date columns back and forth and then copy back into the Input sheet.
    Not necessary -- all you'd need to do is put the offset in a cell, copy, select the dates, Paste > Paste Special, tick Add and Values. I also made a change to add the offset during processing.

    BTW, your tool is quite fragile because of all the named spaces and the header.
    Ouch; I had no issues at all.

    Not knowing what you're doing that's causing problems, I have no suggestion.
    Last edited by shg; 02-18-2019 at 08:41 PM.

  24. #24
    Registered User
    Join Date
    12-13-2020
    Location
    India
    MS-Off Ver
    2016
    Posts
    1

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    How do I get the data for 10 min?

  25. #25
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Help converting OHLC fx data from 1 min to 5 minutes or higher time frame

    Quote Originally Posted by Harjit000 View Post
    How do I get the data for 10 min?
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Convert Time Series OHLC Data Frequency
    By prudential in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-19-2020, 11:50 PM
  2. Replies: 3
    Last Post: 08-10-2016, 10:53 AM
  3. [SOLVED] Converting Time Frame based on Cell Values
    By reyrey in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-06-2013, 10:14 PM
  4. converting minutes to time
    By tommy060289 in forum Excel General
    Replies: 3
    Last Post: 03-09-2012, 12:20 PM
  5. Calculating the minutes for a period during a time frame
    By aquajock98 in forum Excel General
    Replies: 0
    Last Post: 07-29-2011, 06:55 PM
  6. Converting hours and minutes in military time to minutes
    By Argile79 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-13-2010, 02:42 PM
  7. Time - converting HH:MM:SS to Minutes
    By Noel S Pamfree in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-08-2005, 01:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1