For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Datafeed logging starts late
-
Hello there,
I don't know when did this start happening. The script logs the data feed like 50+ bars late. I have tested from 2 other data feed, the problem persists.
Here's the data settings (As you can see the data should start from at 1st of January 2000:
data = bt.feeds.YahooFinanceCSVData( dataname="data/oracle.csv", dtformat=2, fromdate=datetime.datetime(2000,1,10), todate=datetime.datetime(2001,12,29), reverse=False, adjclose=False)
Here's the log (You can see that it starts from 22 April 2000):
When I check the chart, it starts from 3rd of January (Close: 29.5) which is the datetime it should start logging from, because there was no 1-2 January 2020 data in the datafeed:
Here's the def next(self) #Location of the logging function
class TestStrategy(bt.Strategy): tradeperiod = 0 tradecount = 0 params = dict( pfast=10, pslow=20, ) def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries self.dataclose = self.datas[0].close self.dc = DonchianChannels() # To keep track of pending orders and buy price/commission self.order = None self.buyprice = None self.buycomm = None self.mai = None # SMA use sma1 = bt.ind.SMA(period=self.p.pfast) # fast moving average sma2 = bt.ind.SMA(period=self.p.pslow) # slow moving average self.crossover = bt.ind.CrossOver(sma1, sma2) # crossover signal # ATR use self.dataclose = self.datas[0].close self.datahigh = self.datas[0].high self.datalow = self.datas[0].low self.datapreviousclose = self.datas[0].close(-1) self.atr = 0 # self.my_atr = bt.ind.ATR(period = 14,) # LOGGING FUNCTION def log(self, txt, dt=None): ''' Logging function for this strategy''' dt = dt or self.datas[0].datetime.date(0) print('%s, %s' % (dt.isoformat(), txt)) def next(self): cash = self.broker.get_cash() # ATR FUNCTION range_total = 0 for i in range(-13, 1): x = self.datahigh[i] - self.datalow[i] y = self.datahigh[i] - self.datapreviousclose[i] z = self.datalow[i] - self.datapreviousclose[i] if x > y: temp_truerange = x else: temp_truerange = y if temp_truerange > z: true_range = temp_truerange else: true_range = z range_total += true_range self.atr = range_total / 14 # Simply log the closing price of the series from the reference self.log('Close: %.2f , ATRx1: %.2f ,Trailing: %.2f' % ( self.dataclose[0], (self.atr * 1), (self.datapreviousclose - (self.atr * 1)))) # count how many days in tradecount if self.position: self.tradeperiod += 1 else: self.tradeperiod = 0 # Check if an order is pending.. if yes, cant send a 2nd order. if self.order: return
Anyone knows what is the problem here?
-
I meant "22 March 2000" not April.