Maybe try something list this.. Initialize empty list during init, and add to it during next(). Finally, during stop(), combine into a df and export/use for your own purposes.
@Ronan-Dunham said in How to get the data as array of the sma1 and sma2:
class SmaCross(bt.SignalStrategy): def __init__(self): sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30) crossover = bt.ind.CrossOver(sma1, sma2) self.signal_add(bt.SIGNAL_LONG, crossover) self.ma1 = [] # Initialize empty lists to hold indicator values self.ma2 = [] # Initialize empty lists to hold indicator values def next(self): # Create data frame columns here by appending data to a list self.ma1.append(sma1) self.ma2.append(sma2) def stop(self): # Combine and export pandas DataFrame here cerebro = bt.Cerebro() cerebro.addstrategy(SmaCross) store = alpaca_backtrader_api.AlpacaStore(key_id=ALPACA_API_KEY,secret_key=ALPACA_SECRET_KEY,paper=ALPACA_PAPER) DataFactory = store.getdata data0 = DataFactory( dataname=symbol_to_check, timeframe=bt.TimeFrame.TFrame("Minutes"), fromdate=pd.Timestamp('2019-11-15'),compression =1, # todate=pd.Timestamp('2018-11-17'), historical=True) cerebro.adddata(data0) cerebro.run() cerebro.plot()