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/

    ExponentialMovingAverage(EMA)

    General Code/Help
    2
    3
    404
    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.
    • hhh ggg
      hhh ggg last edited by

      Does anyone know:
      What is multiplier value in the default EMA function?
      How to set the multiplier in the EMA function?

      EMA = Closing price x multiplier + EMA (previous day) x (1-multiplier)

      https://www.backtrader.com/docu/indautoref/#exponentialmovingaverage

      1 Reply Last reply Reply Quote 0
      • run-out
        run-out last edited by

        Have a look at the code it might help.

        class ExponentialMovingAverage(MovingAverageBase):
            '''
            A Moving Average that smoothes data exponentially over time.
            It is a subclass of SmoothingMovingAverage.
              - self.smfactor -> 2 / (1 + period)
              - self.smfactor1 -> `1 - self.smfactor`
            Formula:
              - movav = prev * (1.0 - smoothfactor) + newdata * smoothfactor
            See also:
              - http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average
            '''
            alias = ('EMA', 'MovingAverageExponential',)
            lines = ('ema',)
        
            def __init__(self):
                # Before super to ensure mixins (right-hand side in subclassing)
                # can see the assignment operation and operate on the line
                self.lines[0] = es = ExponentialSmoothing(
                    self.data,
                    period=self.p.period,
                    alpha=2.0 / (1.0 + self.p.period))
        
                self.alpha, self.alpha1 = es.alpha, es.alpha1
        
                super(ExponentialMovingAverage, self).__init__()
        

        RunBacktest.com

        hhh ggg 1 Reply Last reply Reply Quote 0
        • hhh ggg
          hhh ggg @run-out last edited by

          @run-out Thank you!!! :)

          1 Reply Last reply Reply Quote 1
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors