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



  • 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()?


  • administrators

    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
      

Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.