For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Custom Indicator Arnaud Legoux Moving Average (Vectorised or Nan-Vec): Help Needed
-
Have anyone done an indicator on this that they would be willing to share? I'm interested in both Normal and Vectorised approaches.
(https://stackoverflow.com/questions/46990098/arnaud-legoux-moving-average-and-numpy)
I am not experienced in sub-classing/inheritance in Python
Any help would be highly appreciated. Thx in advance! -
Anybody has any custom indicator examples which includes numpy calculations? I would be appretiated if you share so i can figure out how to convert the code below.
def NPALMA(pnp_array, a) : length = a # just some number (6.0 is useful) sigma = 6 # sensisitivity (close to 1) or smoothness (close to 0) offset = 0.85 asize = length - 1 m = offset * asize s = length / sigma dss = 2 * s * s alma = np.zeros(pnp_array.shape) wtd_sum = np.zeros(pnp_array.shape) for l in range(len(pnp_array)): if l >= asize: for i in range(length): im = i - m wtd = np.exp( -(im * im) / dss) alma[l] += pnp_array[l - length + i] * wtd wtd_sum[l] += wtd alma[l] = alma[l] / wtd_sum[l] return alma
-
@Ender-Kina were you able to solve this?
-
@Ender-Kina this my ALMA implementation as backtrader indicator
class ALMA(bt.Indicator): lines = ('alma',) params = dict( period=40, sigma=6, offset=1, ) ''' ALMA - Arnaud Legoux Moving Average, http://www.financial-hacker.com/trend-delusion-or-reality/ https://github.com/darwinsys/Trading_Strategies/blob/master/ML/Features.py ''' def __init__(self): self.asize = self.p.period - 1 self.m = self.p.offset * self.asize self.s = self.p.period / self.p.sigma self.dss = 2 * self.s * self.s def next(self): try: wtd_sum = 0 self.l.alma[0] = 0 if len(self) >= self.asize: for i in range(self.p.period): im = i - self.m wtd = np.exp( -(im * im) / self.dss) self.l.alma[0] += self.data[0 - self.p.period + i] * wtd wtd_sum += wtd self.l.alma[0] = self.l.alma[0] / wtd_sum print(self.l.alma[0]) except TypeError: self.l.alma[0] = 0 return