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 customize my own Sizer and calculate the size for the long or short position ?

    Indicators/Strategies/Analyzers
    2
    2
    676
    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.
    • R
      ramoslin02 last edited by

      I backtest my own strategy, and customize my own sizer like following:

          class MySizer(bt.Sizer):
              def _getsizing(self, comminfo, cash, data, isbuy):
                  size = cash*0.96/data.close[1]
                  return size
      

      the above is for the long position, but how do I customize the short position ? maybe for the using the leverage . Thanks .

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

        @ramoslin02 said in How do I customize my own Sizer and calculate the size for the long or short position ?:

        the above is for the long position, but how do I customize the short position ?

        By checking the parameter isbuy which tells you if the sizing operation is for a buy order. Else it will be a sell

        See Docs - Sizers - Smart Staking

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