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/

    How do I print (ATR)

    General Code/Help
    3
    7
    137
    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.
    • G
      Gleetche last edited by

      Hello,

      How do I print bt.ind.ATR?

      and if possible

      How do I make a plot a trailing ATR stop loss? Does anyone know a tutorial/guide where I can learn this?

      1 Reply Last reply Reply Quote 0
      • J
        Jonny8 last edited by

        Hi Gleetche,

        I guess your code would help to answer your question.

        Best

        G 1 Reply Last reply Reply Quote 1
        • G
          Gleetche @Jonny8 last edited by

          @Jonny8 Ohh okay.

          These is my atr line.

          def __init__(self):
          
              self.my_atr = bt.ind.ATR(period = 14)
          

          and I am trying to make this work.

              def next(self):
                  # Simply log the closing price of the series from the reference
                  self.log('Close: %.2f , ATR: $.2f' % (self.dataclose[0],self.my_atr))
          

          But it won't run.

          4911924b-030d-4907-9f9f-6caff66ef866-image.png

          I am trying to get the log ATRin the terminal because it is difficult to see the value of ATR in the graph.
          20c76b25-dc47-4d24-8a71-f22084c6106d-image.png

          J 1 Reply Last reply Reply Quote 0
          • J
            Jonny8 @Gleetche last edited by

            @Gleetche said in How do I print (ATR):

            def next(self):
                # Simply log the closing price of the series from the reference
                self.log('Close: %.2f , ATR: $.2f' % (self.dataclose[0],self.my_atr))
            

            I think replacing the $ after "ATR:" with a % should do the trick.

            Best

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

              @Jonny8 said in How do I print (ATR):

              self.my_atr

              Try using square quotes after this

              self.atr[0]
              

              RunBacktest.com

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

                Sorry, typo.

                self.my_atr[0]
                

                RunBacktest.com

                1 Reply Last reply Reply Quote 1
                • G
                  Gleetche last edited by

                  thanks! it worked

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