For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

importing 4 hour interval csv data

  • Re: 4 hour time intervals

    Hi All,

    Sorry to resurrect an old topic but it is exactly what I am looking for

    My understanding the compression is only to create (in this case) 4 hour data from smaller time frame data.

    What if my raw/original data is 4 hour data. How can keep the time frame after importing?

    Thanks so much in advance



  • administrators

    Same as done in the thread you reference:

    @kreut said in 4 hour time intervals:

    @ab_trader Definitely a step in the right direction! I've updated my code:

    data = btfeeds.GenericCSVData(
        fromdate=datetime.datetime(2000, 1, 1),
        todate=datetime.datetime(2018, 12, 31),
        timeframe=bt.TimeFrame.Minutes, compression=240,
        dtformat=('%Y-%m-%d %H:%M:%S'),

  • @backtrader

    Dear Administrators, thanks for your response
    I have read that thread before but I could not get it working and got confused at the same time.
    The related codes seem to be the "timeframe=bt.TimeFrame.Minutes, compression=240"
    From the wording and trials that I've done, I can only understand it as resampling minutes data into 4 hour data hence the 240 (4 hour = 240 minutes).

    But what I am trying to do is that the raw csv data is 4 hour data from the very beginning. How to import it and keep the time/hour data? I cannot use minutes data because they are not available from the broker that I am using.

    Thanks again for the response and hopefully there is more to come



  • administrators

    Sorry you are confused. That code is loading a data feed and stating that it is made of price bars, with each bar representing 240-Minutes (i.e.: 4-hours)

    It is doing exactly what you asked for.

    There is no resampling in that code. Data feeds do not resample anything. For how resampling is done see: Docs - Data Resampling

    @darwinps said in importing 4 hour interval csv data:

    How to import it and keep the time/hour data?

    You show absolutely no code, no data, so nobody can know what you are doing and why it isn't working

  • @backtrader

    Hi Administrators,

    Thanks for your reply. I still haven't got it working as expected yet but at least now I am sure I am at the right direction. I am sure I can get it.

    Thanks again


  • @backtrader

    Dear All,

    I figured it out. I had the datetime only: <datetime>, <open>, <so forth> instead of <datetime>, <time>, <open>,<so forth>
    Thanks again


Log in to reply