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
-
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'
-
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))