Resample data with timeframe.days at specific (non-midnight) time
I'm interested in using an indicator that uses daily candles, not from 0:00a to 11:59p, but rather from 4:16p to 4:15p. Can I do this using the
cerebro.resampledata(), perhaps with the
If not, is there another way?
sessionendparameter of the data feed which is going to be resampled. It is a parameter for all data feeds, because it is inherited from the superclass.
That worked perfectly, thanks @backtrader.
It wasn't clear how sessionend and sessionstart parameters are used in other places in the engine. My next challenge is that I want to start the session at 600p and end at 415p. setting the sessionstart param did not solve this, My daily candles are still going form 415 to 415.
My daily candles are still going form 415 to 415
The best thing would be that you show what you do and how you come to the conclusion that the daily candle goes from 04:15 to 04:15.
In any case your problem is probably the resolution of your timeframe. A
sessionstartlarger than a
sessionendmakes only sense when you have a sub-day timeframe. Else it would be a running-backwards session.
Is it possible to change the
sessionendparameter in cerebro.resampledata?
cerebro = bt.Cerebro() cerebro.addstrategy(strat) data = btfeeds.GenericCSVData( # 1-min csv feed dataname = datapath, fromdate = startDate_feed, todate = endDate, nullvalue = 0.0, openinterest = -1, timeframe = bt.TimeFrame.Minutes, sessionend = session_End, dtformat = ('%m/%d/%Y'), tmformat = ('%H:%M'), time=1, open=2, high=3, low=4, close=5, volume=6) # Add the 1m Data Feed to Cerebro cerebro.adddata( data, name = 'a0_Hf') # create a daily data feed with standard session end time (session_End) cerebro.resampledata(data, name = 'a0_d1a', timeframe = bt.TimeFrame.Days, compression = 1) # create a daily data feed with a different session end time cerebro.resampledata(data, name = 'a0_d1b', timeframe = bt.TimeFrame.Days, compression = 1, sessionend = datetime.time(14,15))
I want two 1-day resampled feeds with different
sessionend. One idea I had was to feed the CSV data in twice with the different
sessionend. I think that would work, but I was hoping I could do this using only resample data. Thoughts?
It seems the whole platform takes the
sessionendparameter from the first feed, and ignores it later on, even if I leave it empty/default.
A resampled version of a data feed must have the same
sessionendas the original.
Li Mike last edited by
@backtrader In chinese future market, sessionstart is 21:00 and sessionend is 15:00 next day. So, you see sessionstart is indeed larger than session end. Can backtrader process this situation correctly?