@Dennis-Musingila said in Some trades are executing while most are not:
ou can see that sometimes it skips months only to come back to them later how can i fix that
This would suggest that there's a problem with your data. Have you sorted the data by date correctly?
I'm using linode and it works well. You can custom select how powerful your server is but you need to get approved to use the dedicated servers to really get many cpus.
One note though, and I learned this the hard way, you have to kill your server completely when not in use or you keep paying, even if shut down. Create an image and just restart from the image everytime you use it.
This all still costs some money, but the time saving is enormous.
Ok I played around a bit and got it working:
from __future__ import (absolute_import, division, print_function,
# Import the backtrader platform
import backtrader as bt
lines = ('smaSlow','smaFast',)
params = (('periodSlow', 200),('periodFast', 100),('movav', bt.indicators.MovAv.Simple),)
plotinfo = dict(subplot=False)
plotlines = dict(
movavSlow = self.p.movav(self.data, period=self.p.periodSlow)
movavFast = self.p.movav(self.data, period=self.p.periodFast)
self.l.smaSlow = movavSlow #bt.Cmp(movav, self.data)
self.l.smaFast = movavFast #bt.Cmp(movav, self.data)
if self.lines.smaFast[-1] < self.lines.smaSlow[-1] and self.lines.smaFast > self.lines.smaSlow:
signal = True
signal = False
data should be bt data feed object. In your script data is a list of data feed objects, but not a single data feed object. Each data feed should be added to cerebro using separate adddata call. Search the forum, look up the docs and articles, this was discussed tons of times and described well.
@dasch :facepalm: Thank you so much! It's so obvious now, the only reason it was working before with non-live data was because preload parameter defaults to true with non-liva data. If I manually set preload as false when using GenericCSVData, the same behaviour occurs & the current value of the indicator is alway nan.
Updated my strategy so it now looks at the indicator values in the past, it is working as intended.
I suspected that this could be a timezone mis-match issue so I tried changing IB's timezone to UTC (GMT+0) and setting the expiry time works fine now.
I think what happens is this:
Backtrader's does this (pseudocode):
dt = current date & time in UTC
expiry_date_time = dt + valid
place order with expiry_date_time
Order reaches IB. On IB's end, expiry_date_time is interpreted in the user's IB client's timezone (e.g. for someone running IB in australia, expiry_date_time is assumed to be in australia's timezone).