For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
2019-10-02: The community is currently in read-only mode

Error with strategy developing, with csv data



  • Hello everyone, I trying to test my trading strategy using my own data( BTC/USD 15 min candles from bitfinex). But from something reason I got this error

    AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Indicat' object has no attribute 'data1'
    

    The data is in csv format and looks like:

    datetime,open_price,high_price,low_price,close_price,volume
    2018-06-09 21:00:00,7634.2,7634.3,7621.2,7621.2,27.53284099
    2018-06-09 21:15:00,7621.3,7621.3,7621,7621.1,36.04568984
    2018-06-09 21:30:00,7621.3,7630.4,7621.2,7623.1,118.79441082
    2018-06-09 21:45:00,7621.9,7623.1,7621,7621.1,13.6309668
    2018-06-09 22:00:00,7621.1,7621.1,7599.7,7604.2,40.84777833
    

    My code

    from datetime import datetime
    import backtrader as bt
    import backtrader.feeds as btfeeds
    from pprint import pprint
    import backtrader.analyzers as btanalyzers
    
    class SmaCross(bt.SignalStrategy):
        def __init__(self):
            hma = bt.ind.HullMovingAverage(30)
            crossover = bt.ind.CrossOver(self.data.close, hma)
            self.signal_add(bt.SIGNAL_LONG, crossover)
    
    cerebro = bt.Cerebro()
    cerebro.addstrategy(SmaCross)
    cerebro.addanalyzer(btanalyzers.SharpeRatio, _name='mysharpe')
    
    
    data0 = btfeeds.GenericCSVData(
        dataname='f.csv',
        nullvalue=0.0,
        fromdate=datetime(2018, 12, 1),
        datetime=0,
        open=1,
        high=2,
        low=3,
        close=4,
        volume=5,
        openinterest=-1
    )
    cerebro.adddata(data0)
    
    statistics = cerebro.run()
    cerebro.plot()
    
    

    Thanks,
    arrmlet


  • administrators

    @arrmlet said in Error with strategy developing, with csv data:

    hma = bt.ind.HullMovingAverage(30)
    

Log in to reply
 

});