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.
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?
@anil-bhatt said in How to calculate Chaikin Money Flow:
# Let the indicator get enough data
That's not needed and it will probably hurt. But without knowing how and when the values differ ...
@jacob said in Indicator using multi datafeed: operate only on overlapping bar:
this is a great workaround for this issue/bug.
This is not a workaround. It is clearly stated in the FAQ: Community - FAQ
The system cannot know which timeframe/compression your data feed has unless you tell the system.
Indicators are designed to know nothing about datetime. The period they operate is measured in price bars (groups of OHLC price components)
This in turn allows to create indicators on indicators.
You may of course design a custom indicators which require the source data to carry a datetime payload.
The period starts counting at the current bar and goes backwards (it cannot obviously go forward)
See, I do understand that your code is yours, but that is far away from being any test script.
Furthermore, it is for sure not part of any test script because the indentation is wrong which would immediately generate a SyntaxError.
The easiest way, also for you, to reproduce the error and really narrow it down to the lack of a params definition is to define a very simple script which actually reproduces the error. See for example this in your script
What's func_ind? Without ruling out a problem in backtrader itself, you may be passing the wrong thing to addindicator. Just a long shot.