Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    How to plot between times (not dates) using start and end

    General Code/Help
    1
    2
    16
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      stevenm100 last edited by

      Hey,
      I pull in data from yahoo finance with the premarket data. I need to use the premarket for calculations, but dont want to print it when plotting.
      I saw that plot has a start= and end= argument, but i cant get this to work on times. The only example i can find is with dates.
      https://www.backtrader.com/docu/plotting/ranges/plotting-date-ranges/
      Ive tried passing a datetime.time() and datetime.datetime(), but cant get either to work.
      Can anyone share how to plot between certain times?

      cerebro.plot(style='candlestick', start=datetime.datetime(hour=9,minute=30), end=datetime.datetime(hour=16,minute=0))
      

      doesnt work as im missing the date component, seems messy to go to the dataframe to pull out the date in order to re-enter it in the cerebro.plot()

      and

      cerebro.plot(style='candlestick', start=datetime.time(hour=9,minute=30), end=datetime.time(hour=16,minute=0))
      

      doesnt work as a datetime.time() is not expected:

      TypeError: '<' not supported between instances of 'datetime.time' and 'int'
      
      S 1 Reply Last reply Reply Quote 0
      • S
        stevenm100 @stevenm100 last edited by

        This is the monstrosity i was trying to avoid:

        cerebro.plot(style='candlestick', start=datetime.datetime(year=int(df.index.strftime("%Y")[0]),month=int(df.index.strftime("%m")[0]),day=int(df.index.strftime("%d")[0]),hour=9,minute=30), end=datetime.datetime(year=int(df.index.strftime("%Y")[0]),month=int(df.index.strftime("%m")[0]),day=int(df.index.strftime("%d")[0]),hour=16,minute=0))
        
        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors