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/

    Calling self.getsizing() and getting results for self.isbuy() vs. not

    General Code/Help
    2
    2
    815
    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.
    • RandyT
      RandyT last edited by RandyT

      I've been attempting to accomplish scaled in order sizing somewhat outside of the sizer by using order_target_size

      My sizer has a different result for if isbuy vs. not.

      How can I call that logic outside of the sizer with self.getsizing()?

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        This topic somehow got down the ladder without being considered. Let's get down the right ladder which is getting to the core of the question.

        • order_target_size is meant to go to a target, not to execute an order for a specific given size

        • Sizer instances are meant to calculate the size of an order.

          One can of course access the strategy and/or broker attributes and implement a targeting sizer.

        Unlike some other concepts in the backtrader ecosystem, the Sizer instances don't automatically try to locate the surrounding environment (i.e.: finding out where it is being instantiated and therefore in which Strategy instance it is being created)

        If the question is being rightly understood, this is an advantage in this situation. Accessing the logic could be done like this:

        • Create the desired Sizer manually in the strategy in which is going to be executed (and keep a reference to it, of course)

        • Manually set the broker attribute of the sizer: thesizer.broker = self.broker

        • Accessing the logic would be done by means of calling:

             thesizer.getsizing(self, data, isbuy)  # where isbuy is a boolean with `True` for long and `False` for short
          
        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors