Strategy execution on different timeframes and multi-data
I'm attempting to complete a system that generates indicators and signals based on a daily timeframe and execute trades against a data feed running on a minute timeframe. As I have written in other threads, I am looking at minute data for the ES and daily data for the SPY. I have set
sessionend=dt.time(16, 00)for the daily timeframe resample of the SPY data so I would only expect to see the daily bar for SPY at 16:00 EST.
Note: I am also making an assumption that the
sessionend=variable is set to the time in the timezone of that instrument and not my local timezone.
next(), how do I ignore the ticks from the minute timeframe data (
data0) and only evaluate conditions based on the daily closing bar (
data1) that the indicators are processing? As it stands, it appears I am hitting
next()for every tick of
I think part of what I am seeing here is a replay of all backfilled data from my IB feed on ES
Here is how I am sourcing data:
# ES Futures Live data timeframe resampled to 1 Minute data0 = ibstore.getdata(dataname=args.live_es, fromdate=fetchfrom, timeframe=bt.TimeFrame.Minutes, compression=1) cerebro.resampledata(data0, name="ES", timeframe=bt.TimeFrame.Minutes, compression=1) # SPY Live data timeframe resampled to 1 Day data1 = ibstore.getdata(dataname=args.live_spy, backfill_from=bfdata0, timeframe=bt.TimeFrame.Days, compression=1, sessionend=dt.time(16, 00)) cerebro.resampledata(data1, name="SPY", timeframe=bt.TimeFrame.Days, compression=1)
After a full replay of backfilled minute
data0 (ES), I now see a tick per minute playing through Strategy
I'd like to ignore these ticks since the only purpose for the ES feed is to execute a trade on that instrument.
nextis called for any tick which any data produces. Concentrating on a specific data is a matter of looking at the
lenof the data.
lenof the data changes (it will always go up) you know you got a tick of that data
def start(self): self.lendata1 = 0 def next(self): if len(self.data1) > self.lendata1: self.lendata1 += 1 do_something_here()
@backtrader thank you sir