Oanda and resampling
-
Merry Christmas everyone.
One of my wife's gifts to me is time to work on my forex project today. So I am tackling a problem that has mystified me for weeks. Here is a snippet of my code:
def runstrategy( currpair ): cerebro = bt.Cerebro() broker = BrokerCls( token='my-token-here', account='my-account-here', practice=True ) cerebro.setbroker(broker) DataFactory = DataCls data = DataFactory( dataname=currpair[0] + '_' + currpair[1], timeframe=bt.TimeFrame.Minutes, compression=5 ) cerebro.resampledata(data , timeframe=bt.TimeFrame.Minutes, compression=60, rightedge=True) cerebro.resampledata(data , timeframe=bt.TimeFrame.Minutes, compression=240, rightedge=True) cerebro.addstrategy() cycles = cerebro.run()
and then:
def next( self ): for i, d in enumerate(self.datas): print(i, d.datetime.datetime(0).strftime('%Y-%m-%dT%H:%M:%S.%f'))
My problem: next() gets invoked for my two resampled timeframes - 60 & 240 minutes - but never for the raw M5 'ticks'. Every output looks like this:
0 2020-12-24T11:00:00.000000 1 2020-12-24T08:00:00.000000
So self.datas[0] contains the first resample (M60) and self.datas[1] contains the second (M240). Where is my M5 data???
I have been working around this by request M1 data and resampling to M5,M60,M240. That way data0,data1,data2 reflect those timeframes. But I need more backfill data on startup, and I think I would get more if I request M5 data instead of M1.
I hope I am just misunderstanding something.
Thanks to any fellow nerds who are active here today. And yes, I realize not everyone celebrates Christmas.
-
hi @leecallen You did not add the ticks to BT but only the resamples ones.
cerebro.adddata(data) would also take ticks in to next ()
-
@rajanprabu said in Oanda and resampling:
cerebro.adddata(data)
Omigod THANK YOU! So fast, so simple, and so right.
It's a festivus miracle!