Yes, that works. Problem is that my other model provides output in string format. I don't want to map the values. Regards.

Best posts made by monil shah 0
-
RE: Can we iterate string as datafeed?
Latest posts made by monil shah 0
-
RE: broker.get_value() return NaN after i add pyfolio analyzer
Getting the same error for pyfolio. Please let me know if you get some help
-
Resample indicator in init function
This is an example code for my problem. Any particular way if I can resample the data in init function.
class firstStrategy(bt.Strategy): def __init__(self): # TODO: Resample data to daily, weekly or monthly self.pivot = bt.indicators.PivotPoint(self.data) def next(self): print("{} C: {} PP: {}".format(self.data.datetime.datetime(), self.data.close[0], self.pivot.lines.p[0])) # Variable for our starting cash startcash = 10000000000 # Create an instance of cerebro cerebro = bt.Cerebro() # Add our strategy cerebro.addstrategy(firstStrategy) data = store.getdata(dataname='AAPL', historical=True, timeframe=bt.TimeFrame.Minutes, compression=5, fromdate=datetime.date(2020, 5, 26), todate=datetime.date(2020, 8, 30)) # Add the data to Cerebro cerebro.adddata(data) # cerebro.resampledata(data, name='data2', timeframe=bt.TimeFrame.Minutes, compression=5) # Set our desired cash start cerebro.broker.setcash(startcash) # Run over everything strategies = cerebro.run() firstStrat = strategies[0] # Get final portfolio Value portvalue = cerebro.broker.getvalue() # Print out the final result print('Final Portfolio Value: ${}'.format(portvalue)) # Finally plot the end results cerebro.plot(style='candlestick')
-
Did we get any solution?
Re: Does Backtrader support Parallel Strategies?
Any solution for this?
-
How to shut live trade from outside the strategy?
I am following this blog
It has amazing way to shut the live trade from inside the strategy. Is there any way that I can shut the live trade from outside the strategy i.e. after execution of line cerebro.run()
-
RE: Can we iterate string as datafeed?
Yes, that works. Problem is that my other model provides output in string format. I don't want to map the values. Regards.
-
Can we iterate string as datafeed?
I am using indicators value to run few of my strategies, for which I need to iterate it over string.
import backtrader as bt import pandas import backtrader.feeds as btfeeds class StratData(btfeeds.PandasData): lines = ('Signal',) params = ( ('open', None), ('high', None), ('low', None), ('close', None), ('volume', None), ('openinterest', None), ('Signal', 'Signal') ) class StrategyPrint(bt.Strategy): def next(self): print('%03d , %f' % ( len(self), self.data.l.Signal[0],)) # Create a cerebro entity cerebro = bt.Cerebro(stdstats=False) # Add a strategy cerebro.addstrategy(StrategyPrint) dataframe = pandas.read_csv(datapath, index_col=0) print('--------------------------------------------------') print(dataframe) print('--------------------------------------------------') # Pass it to the backtrader datafeed and add it to the cerebro data = StratData(dataname=dataframe) cerebro.adddata(data) # Run over everything cerebro.run()
CSV File:
Date,Signal
01-04-2020 08:00,RUN
02-04-2020 08:00,STOP
03-04-2020 08:00,STOP
04-04-2020 08:00,RUN
05-04-2020 08:00,RUNError Log:
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\backtrader\cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\backtrader\cerebro.py", line 1212, in runstrategies data.preload() File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\backtrader\feed.py", line 438, in preload while self.load(): File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\backtrader\feed.py", line 479, in load _loadret = self._load() File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\backtrader\feeds\pandafeed.py", line 255, in _load line[0] = self.p.dataname.iloc[self._idx, colindex] File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\backtrader\linebuffer.py", line 222, in __setitem__ self.array[self.idx + ago] = value TypeError: must be real number, not str
-
How to run multi-data multi-strategy on Oanda live feed
I need an idea to run multi-data multi-strategy on Oanda. Problem I am facing is that every broker provides only one websocket to individual account therefore I can not run multiple-script at a time. Does anyone has any suggestion?
Thanks
-
Pause live trading in Oanda
Hi! Thanks for this amazing code. I am using Oanda for live trading which is deployed on VPS. How can I pause the program when there is no live bar? Example: At 3:30 pm the program should go in sleep mode and get activated next day at 9:15 am.
Should I use- Celery or RabbitMQ to pause the whole program
- internal code modification to send backtrader in sleep mode.