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/

    Calculate EMA on the median ((high+low/2)) ?

    General Code/Help
    3
    7
    119
    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.
    • Dallascat
      Dallascat last edited by

      Where can I change the data point from the close to the median price? Also, how can I increase the decimal's displayed for an indicator? For example, a TRIX indicator that shows x.xx values default and be able to display x.xxxx. Thanks!!

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

        To get a line for ema as you ask...

        self.myema = bt.ind.EMA((self.datas[0].high / self.datas[0].low) /2 )
        

        When printing use the format

        :.4f
        
        Dallascat 1 Reply Last reply Reply Quote 2
        • Dallascat
          Dallascat @run-out last edited by

          @run-out said in Calculate EMA on the median ((high+low/2)) ?:

          To get a line for ema as you ask...

          self.myema = bt.ind.EMA((self.datas[0].high / self.datas[0].low) /2 )
          

          Thanks, so I am getting an error:

          "....bt.indicators.ExponentialMovingAverage((self.datas[0].high / self.data[0].low) /2, period=100)
          AttributeError: 'float' object has no attribute 'low' "

          Original code for the EMA: bt.indicators.ExponentialMovingAverage(self.datas[0], period=100)

          Updated to do the median: bt.indicators.ExponentialMovingAverage((self.datas[0].high / self.data[0].low) /2, period=100)

          and getting that error.

          Thanks for your help!

          1 Reply Last reply Reply Quote 1
          • A
            ab_trader last edited by

            it should be:

            bt.indicators.ExponentialMovingAverage((self.datas[0].high / self.datas[0].low) /2, period=100)

            Dallascat 1 Reply Last reply Reply Quote 2
            • Dallascat
              Dallascat @ab_trader last edited by

              @ab_trader Thank! Rookie mistake....ok, so it complies with no errors but gives the wrong value. I'm running it on the SPY daily, which the 100EMA(close) plots fine (305ish), but the new code for the 100EMA(median), gives a value way low (0.51). Ideas?

              1 Reply Last reply Reply Quote 0
              • A
                ab_trader last edited by

                This should fix your issues:
                bt.indicators.ExponentialMovingAverage((self.datas[0].high + self.datas[0].low) /2, period=100)

                Dallascat 1 Reply Last reply Reply Quote 2
                • Dallascat
                  Dallascat @ab_trader last edited by

                  @ab_trader Thanks for all your help here and a few other posts! !

                  1 Reply Last reply Reply Quote 1
                  • 1 / 1
                  • First post
                    Last post
                  Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
                  $(document).ready(function () { app.coldLoad(); }); }