CSV Data
-
Hi all,
I'm new to backtrader and I'm trying to feed the platform with custom data. However, I could not get the algo run and trade properly. I believe the problem is coming from the data itself but I have no clue how to fix it. Please see my code below and greatly appreciate your help.
import backtrader as bt import backtrader.feeds as btfeed class Tickstory(btfeed.GenericCSVData): params = ( ('dtformat', '%m/%d/%Y %H:%M:%S'), ('tmformat', '%H:%M:%S'), ('datetime', 0), ('time', -1), ('open', 1), ('high', 2), ('low', 3), ('close', 4), ('volume', 5), ('openinterest', -1), ('timeframe', bt.TimeFrame.Minutes), ('compression', 1) ) class SmaCross(bt.SignalStrategy): params = (('pfast', 10), ('pslow', 30),) def __init__(self): sma1, sma2 = bt.ind.SMA(period=self.p.pfast), bt.ind.SMA(period=self.p.pslow) self.signal_add(bt.SIGNAL_LONG, bt.ind.CrossOver(sma1, sma2)) cerebro = bt.Cerebro() data = Tickstory(dataname='EURUSD_New.csv') cerebro.adddata(data) cerebro.addstrategy(SmaCross) cerebro.run() cerebro.plot(style='candle')
Data sample:
Timestamp Open High Low Close Volume 8/2/2017 19:00 1.18514 1.1852 1.18506 1.18508 163.9199998 8/2/2017 19:01 1.18508 1.18508 1.18503 1.18505 98.18999887 8/2/2017 19:02 1.18504 1.18504 1.18484 1.18484 97.77999985 8/2/2017 19:03 1.18484 1.18495 1.18483 1.18484 86.52999997 8/2/2017 19:04 1.18484 1.18484 1.18466 1.18471 152.0699996 8/2/2017 19:05 1.18471 1.1848 1.18471 1.18477 55.15999973 8/2/2017 19:06 1.18476 1.18492 1.18476 1.18492 80.6699996 8/2/2017 19:07 1.18491 1.18491 1.18473 1.18479 144.5299996 8/2/2017 19:08 1.18479 1.18494 1.18478 1.18494 132.1899995
-
('tmformat', '%H:%M:%S'),
You don't need to specify that, because it is already in
dtformat
and time is not in a separate field.But that is for sure not source for an error. In any case the chart seems to show everything is ok.
But your winnings and losses are so minuscule (+0.002 at most and close to 0.00x in total) that they have no impact in the the 2 decimals with wich the
Broker
observer displays the values. -
Thank you for your reply. I think something wrong must have happened, I noticed the 'buy' and 'sell' arrows are not displayed on the graph.
Should I test it with more data?