Drawdown analyzer works with the historical broker value curve. You calculate your results based in closed trades equity, no in-trade drawdowns are considered. The results should be different in most of the cases.
It's not a perfect solution. Because the original definition of the RSI doesn't have provisions for the case in which a DivisionByZero happens. This only happens when the prices don't change over time, which was possibly not contemplated by the author, back then.
@coolernax said in Bullish and Bearish Divergence MACD/RSI:
I have created the fix, hope you can include similar indicator for RSI/MACD in the main branch:
lines = ('signal',)
params = dict(
self.hfi = bt.ind.FindFirstIndexHighest(self.data.high, period=self.p.hl_period)
self.lfi = bt.ind.FindFirstIndexLowest(self.data.low, period=self.p.hl_period)
self.rsi = bt.ind.RSI_Safe(period=self.p.rsi_period)
signal = 0
if self.hfp >= self.hsp:
if self.rsi[-int(self.hfi)] < self.rsi[-int(self.hsi)]:
signal -= 1
if self.lfp <= self.lsp:
if self.rsi[-int(self.lfi)] > self.rsi[-int(self.lsi)]:
signal += 1
h_iterable = self.data.get(size=self.p.hl_period, ago=-int(self.hfi) - self.p.hl_min)
l_iterable = self.data.get(size=self.p.hl_period, ago=-int(self.lfi) - self.p.hl_min)
if len(h_iterable) > 0 and len(l_iterable) > 0:
m = max(h_iterable)
self.hsi = next(i for i, v in enumerate(reversed(h_iterable)) if v == m) + int(self.hfi) + self.p.hl_min
m = min(l_iterable)
self.lsi = next(i for i, v in enumerate(reversed(l_iterable)) if v == m) + int(self.lfi) + self.p.hl_min
self.hfp = self.data.high[-int(self.hfi)]
self.hsp = self.data.high[-int(self.hsi)]
self.lfp = self.data.low[-int(self.lfi)]
self.lsp = self.data.low[-int(self.lsi)]
self.lines.signal = self.signal_get()
self.lines.signal = 0
I'm going to deep-dive in the platform once again from the beginning, so then hopefully those questions/topics will be clearer.
Don't you consider having a discord channel for very interactive chats?
@sfkiwi said in DivideZeroError on some indicators:
Ok but, unlikely as it is, the price stayed stationary for more than 20mins so shouldn't the indicators still be protected from a divide by zero error?
Nobody has claimed nothing about the price or the protection. Only that you said something was broken without posting any code or data. And when the code and data were posted, the error was somewhere else. Hence the need to post something sensible.
Extends the Bollinger Bands with a Percentage line
lines = ('pctb',)
params = (('safediv', False), ('safezero', 0.0))
plotlines = dict(pctb=dict(_name='%B')) # display the line as %B on chart
if not self.p.safediv:
self.l.pctb = (self.data - self.l.bot) / (self.l.top - self.l.bot)
self.l.pctb = DivByZero(self.data - self.l.bot, self.l.top - self.l.bot, self.p.safezero)
params = (('safediv', True),)
That's something you can directly use in your code. There is no need for a fork to do that.
You cannot put values into the future, which is what you are trying to do.
Keep the values in a ring buffer (use for example collections.deque with a maxlen during creation), push the last predicted value and pop the value from the left which is the current value.
Apologies for not articulating the problem well enough in the first post. However, you have correctly inferred that I am facing issues with not being able to see intraday positions and returns from PyFolio analyzer.
My run strat function looks like this:
args = parse_args()
# Create a cerebro entity
cerebro = bt.Cerebro(stdstats=True)
# Add a strategy
# Get a pandas dataframe
datapath = ('./dataset/data2.csv')
dataframe = pd.read_csv(datapath,parse_dates=True,index_col=0)
# Pass it to the backtrader datafeed and add it to the cerebro
data = PandasDataExpanded(dataname=dataframe)
# Add PyFolio Analyzer
# Run over everything
strats = cerebro.run()
returns, positions, transactions, gross_lev = pyfoliozer.get_pf_items()
for each in strat0.analyzers:
# Plot the result
if not args.noplot:
My class for pandas data feed look like this:
lines = ('barCount',)
params = (('barCount', -1),)
The lines of all other indicators do actually get plotted, there is no reason why above and below to not get plotted.
@sfkiwi said in Unable to get LinePlotterIndicator to display:
But I am not able to get these values to display on the cerebro.plot(). I read in the docs that because of the use of > and < the lines won't just plot automatically
This is when you make a comparison and is not assigned to a line. In that case one uses LinePlotterIndicator to fake an indicator that holds the resulting operation of the comparison.
Don't you think that an actual plot (you posted an example in the other thread) could help?