Hourly bars?



  • Hi,
    I copy pasted the quickstart code under "The broker says: Show me the money!" and adjusted filename and following feed params:

        data = data = btfeeds.GenericCSVData(
        dataname='test_ForBacktraderHourly.csv',
    
        fromdate=datetime.datetime(2017, 1, 1),
        todate=datetime.datetime(2017, 1, 5),
    
        nullvalue=0.0,
        dtformat=('%Y-%m-%d %H'), # it is hourly data
        
        
        headers = True, 
        datetime=0,
        high=1,
        low=2,
        open=3,
        close=4,
        volume=5,
        openinterest=-1
    )
    

    The csv contains datal like this:
    Date, High, Low, Open, Close, Volume
    2011-09-13 15, 6.000000000000, 5.800000000000, 5.800000000000, 6.000000000000, 25.000000000000
    2011-09-13 16 , 5.950000000000, 5.760000000000, 5.950000000000, 5.760000000000, 22.353982380000

    So that should be hourly bars.
    But when executing the self.buy() the buy is not executed at next bar, but at next day.
    How to change from Daily to Hourly?
    I tried to add

        timeframe = bt.TimeFrame.Hours
    

    but 1) this is only used for Resampling (dont know yet what it is) and 2) does Hours not exist.

    edit:
    So question is not only about "hourly" it is about customized bars, so even 2 hourly or 0.5hourly and so on.


  • administrators

    @Serp said in Hourly bars?:

    timeframe = bt.TimeFrame.Hours

    but 1) this is only used for Resampling (dont know yet what it is) and 2) does Hours not exist.

    No, ``timeframe` is not only for resampling. It is a standard parameter for all data feeds. It is especially important when resampling because a target is needed.

    Which means that if your input is really not Days (the default value), you have to tell the platform what it is.

    1. does Hours not exist.

    You can still use Minutes and 60 which is 1 hour.



  • thank you very much. English is not my native language and I thought the sentence:
    "Informative unless Data Resampling/Replaying is used" would mean, that it is just for my personal informative use (like I could print that it is "daily", but it has no other purpose).

    Thanks, so to sum it up (for other people reading here) the solution was:

     timeframe = bt.TimeFrame.Minutes, 
     compression = 60,

  • administrators

    You read it right and has been corrected. The platform was tightened around that area due to how users were actually addressing the multiple possible corners.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.