Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    ALMA: Arnaud Legoux Moving Average

    Indicators/Strategies/Analyzers
    1
    1
    355
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Mariano Volpedo
      Mariano Volpedo last edited by

      Another trend indicator: ALMA
      From http://www.financial-hacker.com/trend-delusion-or-reality/

      Appreciate you feedback for bugs or omissions

      Ps: "alma" means soul in spanish

      class ALMA(bt.Indicator):
          lines = ('alma',)
      
          params = dict(
                          period=40,
                          sigma=6,
                          offset=1,
                      )
          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
      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors