Use opening price for submission check for Market orders when
cheat-on-open is active
Update pnlcomm on all operations and not just profit/loss locking
Correct comment for fillalpha and add baralpha for candlestick opacity
Merge PR 378 (doc typo) PR 378 (rollover for live feeds and tz use
in datetime utilities)
Use internal dict for data feed presence test and update trade observer
There is no trace of a single indicator in your code, neither custom nor not-custom. It is therefore 100% unclear what your code and text have to do with indicators.
There is a sell signal on the chart, right at the beginning.
You have a dataframe with a column called signal but you seem to want to act upon a column called action which isn't there.
You probably want to take two steps back, reformat your question, dataframe loading (code formatting, because that code won't execute) and let us know.
Hi all, I'm coded a backtrader version of the Absolute Strength Histogram (ASH) indicator, wonder if I could get some feedback on "proper/optimized" ways of coding it.
Description and calculation of indicator is from : https://www.mql5.com/en/code/21429
My main issue, is that when coding, I created each line bar by bar, primarily in the "next()" function. And when calculating a weighted average, I couldn't seem to get a BT indicator function to work, so used "numpy" functions.
Another questions, most of the "lines" in my code are for calculations/storing values, is there a recommended way to store these data instead? My understanding is that lines should be mainly for plotting/output.
It seems to work, but clearly not optimal, hope for any suggestions! Thanks!
lines = ("SmthBulls", "SmthBears", "Bulls", "Bears", "AvgBulls", "AvgBears", "ash")
params = (("Mode", 0), #RSI = 0, Stoch = 1
plotinfo = dict(plot=False, subplot=True)
self.sma_close = bt.indicators.SMA(self.data, period=1)
self.highest = bt.indicators.Highest(self.data.high, period = self.p.Length)
self.lowest = bt.indicators.Lowest(self.data.low, period = self.p.Length)
if self.p.Mode == 0:
self.l.Bulls = 0.5 * (math.fabs(self.sma_close - self.sma_close[-1]) + (self.sma_close - self.sma_close[-1]))
self.l.Bears = 0.5 * (math.fabs(self.sma_close - self.sma_close[-1]) - (self.sma_close - self.sma_close[-1]))
if self.p.Mode == 1:
self.l.Bulls = self.sma_close - self.lowest
self.l.Bears = self.highest - self.sma_close
if not math.isnan(self.l.Bulls[-1*self.p.Length]) and not math.isnan(self.l.Bears[-1*self.p.Length]):
weights = np.array(range(1, self.p.Length + 1))
avgBullarray = np.array()
avgBeararray = np.array()
for i in range(-1 * self.p.Length+1, 1):
avgBullarray = np.append(avgBullarray, self.l.Bulls[i] )
avgBeararray = np.append(avgBeararray, self.l.Bears[i] )
self.l.AvgBulls = np.average(avgBullarray, weights=weights)
self.l.AvgBears = np.average(avgBeararray, weights=weights)
if not math.isnan(self.l.AvgBulls[-1*self.p.Smooth]) and not math.isnan(self.l.AvgBears[-1*self.p.Smooth]):
weights = np.array(range(1, self.p.Smooth + 1))
smthBullarray = np.array()
smthBeararray = np.array()
for i in range(-1 * self.p.Smooth+1, 1):
smthBullarray = np.append(smthBullarray, self.l.AvgBulls[i] )
smthBeararray = np.append(smthBeararray, self.l.AvgBears[i] )
self.l.SmthBulls = np.average(smthBullarray, weights=weights)
self.l.SmthBears = np.average(smthBeararray, weights=weights)
self.l.ash = self.l.SmthBulls - self.l.SmthBears