For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
array assignment index out of range
-
from future import (absolute_import, division, print_function,
unicode_literals)import datetime # For datetime objects
import os.path # To manage paths
import sys # To find out the script name (in argv[0])Import the backtrader platform
import backtrader as bt
import backtrader.indicators as btind
import mathCreate a Stratey
class TestStrategy(bt.Strategy):
params = (
('maperiod', 15),
)def log(self, txt, dt=None): ''' Logging function fot this strategy''' dt = dt or self.datas[0].datetime.date(0) print('%s, %s' % (dt.isoformat(), txt)) def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries self.dataclose = self.datas[0].close # To keep track of pending orders and buy price/commission self.order = None self.buyprice = None self.buycomm = None # Add a MovingAverageSimple indicator self.sma = bt.ind.SMA(self.datasclose, period = 40)
-
Please check the following similar posts (probably you may have the same problem):
https://community.backtrader.com/topic/407/indexerror-array-assignment-index-out-of-range
https://community.backtrader.com/topic/1797/getting-indexerror-array-assignment-index-out-of-range-in-cerebro-run -
You may want to share the full script.