在backtrader中,自定义一个画线指标,要求指标默认值为空。但可在自定义策略时改变它的值
Jump to turn (8)
- 1在backtrader中,自定义一个画线指标,要求指标默认值为空。但可在自定义策略时改变它的值
- 2但出借了,提示如下AttributeError: 'LinesLineSeriesLineIteratorDataAccessorIndicat' object
- 3请修正上一段代码
- 4class EntryLine(bt.Indicator): lines = ('entryprice',) plotinfo = dict(subplot=F
- 5self.lines.myline[0] = self.params.defaultvalue这里出错,TypeError: must be real numb
- 6程 序运行成功,但只能画出横线啊,只能改变一次值么?
- 7出错AttributeError: 'LinesLineSeriesLineIteratorDataAccessorIndicat' object has no
- 8TypeError: MyIndicator.init() got an unexpected keyword argument 'defaultvalue'
- User
在backtrader中,自定义一个画线指标,要求指标默认值为空。但可在自定义策略时改变它的值
- Assistant
实现自定义画线指标,需要继承backtrader中的Indicator类,并重新实现__init__()和next()方法。指标默认值可以在__init__()方法中设置为空。可以在自定义策略中改变指标值,只需要调用指标实例的__init__()方法即可。
以下是一个示例代码:
codeimport backtrader as bt class MyIndicator(bt.Indicator): lines = ('myline',) params = (('mydefault', None),) def __init__(self): self.lines.myline = bt.LinePlotterIndicator(self, name='MyLine') def next(self): self.lines.myline[0] = self.params.mydefault在调用自定义策略时,可以通过以下方式改变指标值:
code