HI Alpaca forum community,
I need sma1 and sma2 and date and closing price of a stock that is calculated in below code. I tried all my best to extract this data from the code below but somehow could not get the final data in a dataframe. Can someone help with this please? All I need is a dataframe with columns: DateTime, Closing Price, SMA1(which is 10 SMA) and SMA2(which is 30SMA) as seen in the picture. Any help is much appreciated.
Below is the code:
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)
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()
