For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Setting Sizer within Strategy Next for Bitcoin



  • We are using the following code in our main application, and it works fine to deal with Fractional assests such as BTC. Basically we are taking the price of BTC, dividing by 100, and that is a single unit for our strategy. The strategy needs to read read from the current balance, then decide how many units it needs to buy. All easy code, but...how do we do this, in the strategy's Class in the next function, so we can dynamically decide how many units to buy based on other data?

    the_stake = number_of_units * .01
    cerebro.addsizer(bt.sizers.FixedSize, stake=the_stake)
    

    Here is the code we use to generate the units if needed.

                    # Determine Size
                    btc_price = self.dataclose[0]
                    balance = self.broker.getvalue()
                    unit_price = btc_price / 100
                    money_in_play = balance * .5
                    units_to_buy = money_in_play // unit_price
                    stake = units_to_buy / 100
                    btc_cost = stake * btc_price
    


  • If I well understood, you probably need to use a mix between multiple data strategy and managing the size of the position in the strategy like I did here


Log in to reply
 

});