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/

    Sizer calculating ATR indicator values

    Indicators/Strategies/Analyzers
    3
    6
    1501
    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.
    • T
      Trade Prophet last edited by

      Is there a way for a sizer to hold the ATR calculation without initializing ATR in the strategy init?
      For design decoupling purposes I would like the sizer to calculate a specific ticker's ATR value and then compute the position size,the ATR calculation should be the sizer's "head ache",not the strategies init ..
      Can a sizer calculate ATR values for data without that ATR been initialized in the strategy?

      this does not seem to calculate ATR values :

          # inside the sizer 
          def _getsizing(self, comminfo, cash, data, isbuy):
              atr = bt.indicators.ATR(data, period=self.atr_parameter) # not initialized in __init__,**always empty ...**
      
              return position_size_that_depends_on_atr  #  crash ..
      
      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        The Sizer instance is created inside the Strategy and the indicator will look for such Strategy to register itself. It has to do it or it wouldn't else work.

        Bottomline: It will still be as if you had done inside the Strategy

        Caveat Emptor: never tried.

        1 Reply Last reply Reply Quote 1
        • T
          Trade Prophet last edited by

          OK,
          Thank you for your reply ( and kudos on the incredible work ..)

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

            Has this been solved? If so is it possible to post the Sizer code? Thanks!

            1 Reply Last reply Reply Quote 0
            • T
              Trade Prophet last edited by

              class AtrBasedPositionSize(bt.Sizer):
                 def __init__(self, atr_parameter, one_bar_risk, atrs):
                     self.atr_parameter = atr_parameter
                     self.atrs = atrs
              
                 def _getsizing(self, comminfo, cash, data, isbuy):
                     if(len(data)<=self.atr_parameter):return 0
                     ticker = data._name
                     position_size = int((self.broker.getvalue()) / self.atrs[ticker][0])
                     return position_size 
              
              1 Reply Last reply Reply Quote 0
              • A
                aaggmm last edited by

                Thanks !

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