this is not a backtrader issue, but mostly a btoandav20 issue or something with your strategy.
do you store the position size somewhere?
but without some workable code I cannot help you that much with your issues.
I discovered your good tool backtrader_addons & start using it. I found a 'ZeroDivisionError: float division by zero' bug when there is no trade in a test.
Below are the stacktrace for your reference.
Traceback (most recent call last):
File "C:/Users/john/PycharmProjects/Backtrader/venv/Include/IBPaperTrade.py", line 83, in <module>
strats = cerebro.run(tradehistory=True) # for trade_list
File "C:\Users\john\PycharmProjects\Backtrader\venv\lib\site-packages\backtrader\cerebro.py", line 1127, in run
runstrat = self.runstrategies(iterstrat)
File "C:\Users\john\PycharmProjects\Backtrader\venv\lib\site-packages\backtrader\cerebro.py", line 1301, in runstrategies
TestStrategy, Bracket, 2020-06-04-030233, Strategies execution completed 0 trade with self.broker.cash=7788592.0392 and self.broker.getvalue()=7788591.99
File "C:\Users\john\PycharmProjects\Backtrader\venv\lib\site-packages\backtrader\strategy.py", line 486, in _stop
File "C:\Users\john\PycharmProjects\Backtrader\venv\lib\site-packages\backtrader\analyzer.py", line 200, in _stop
File "C:\Users\john\PycharmProjects\Backtrader\venv\lib\site-packages\backtrader_addons-0.18.10-py3.6.egg\backtrader_addons\analyzers\limited_test_report.py", line 80, in stop
self.rpt['win_percent'] = 100.0 * win_percent / len(trades)
ZeroDivisionError: float division by zero
Oh alright. I am using Dave Vallance bt-ccxt-store, it must be there the problem lies I know bitmex only delivers ohlc candles of 1m through their api. I was wondering if you could loop to get the live price faster/the last candle but then I know thats where to look for that solution.
Thank you, for the response!
@J-T from your code examples, it is not clear what you are doing.
in a strategy, you could do the following:
self.sizer = btoandav20.sizers.OandaV20Risk(risk_percents=2, stoploss=10)
which will work, when data is a oanda feed
@AlfredSisley said in Adding InfluxDB Datafeeds:
Are you surprised by how long it takes me to run my simple skeleton backtests given my hardware?
Hard to tell, can't directly compare with my local results. Usually I'm backtesting a single ticker at a time, so my mileage may vary.
What's your timing for backtesting a single ticker for, say 5 - 10 years of 1 or 5 minutes bars ?
there is no need to call self.notify_order() in the next(). in order to avoid an error with bar_executed you need to operate with it only if the position exists. otherwsie use of bar_executed is meaningless.
also don't post pictures, but text; please read the note about backticks on top of the page.
BT has built in 'Highest' and 'Lowest' indicators that will do this for you.
For a long time I used it wrong a received inconsistent results. This structure works for me now:
import backtrader as bt
import backtrader.indicators as bt.ind
params = (
self.highest = highest = bt.ind.Highest(self.data, period=self.p.highperiod_0, plot=True, subplot=False)
self.lowest = lowest = bt.ind.Lowest(self.data, period=self.p.lowperiod_0, plot=True, subplot=False)
#LONG POSITION: Breakout high when
self.data.close > self.highest
#SHORT POSITION: Breakout low when
self.data.close() < self.lowest
You need to set the period for the number of bars you want to find the highest/lowest data for. Once you have this static high/low working, try using a dynamic indicator for something a little more complex: