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/

    btoandav20 sizers

    Indicators/Strategies/Analyzers
    2
    4
    95
    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.
    • J T
      J T last edited by

      Hi !
      Does anyone have experience using the btoandav20.sizers.OandaV20Risk ?

      I think it needs to run in strategy class, next method and not in the run strat right?
      I say this because this sizer requires stoploss pips which is dynamic.

      I tried this which probably is rubbish.

      # in Strategy class I have params dict(sizer = None)
      # and in initi the below. I am just following bt docs. 
      def __init__(self):
       if self.p.sizer is not None:
                  self.sizer = self.p.sizer
      
      def next(self):
              if self.one_test_trade:
                  globe.action = 'long'
                  self.one_test_trade = False
                  price = self.data0.close[0] - 0.0001
                  sl_px = price - self.atr[0] * 1.5
                  sl_pips = abs(sl_px - price) / 0.0001
                  limit_px = price + self.atr[0]
                  self.ATR_at_exe = self.atr[0]
      
      self.exe_size = self.sizer.getsizing(btoandav20.sizers.OandaV20Risk, risk_percents=2, stoploss=sl_pips) 
      

      the above returns error although risk_percents is a valid param for this sizer:

      TypeError: getsizing() got an unexpected keyword argument 'risk_percents'
      

      Would some kind souls pls help me with some sample code how this is to be used?

      source code of the sizer is here: https://github.com/ftomassetti/backtrader-oandav20/blob/master/btoandav20/sizers/oandav20sizer.py

      Thanks a miliion!

      1 Reply Last reply Reply Quote 0
      • J T
        J T last edited by

        Re: btoandav20 sizers

        changed to this:

        self.exe_size = btoandav20.sizers.OandaV20Risk(risk_percents=2, stoploss=sl_pips).getsizing(data=self.data0.close[0], isbuy=True)
        

        which returns error:

        comminfo = self.broker.getcommissioninfo(data)
        AttributeError: 'NoneType' object has no attribute 'getcommissioninfo'
        

        and added this in runstrat:

        comminfo = forexSpreadCommisionScheme(spread=3, acc_counter_currency=False)
        cerebro.broker.addcommissioninfo(comminfo)
        

        Error is still the same.

        comminfo = self.broker.getcommissioninfo(data)
        AttributeError: 'NoneType' object has no attribute 'getcommissioninfo'
        
        D 1 Reply Last reply Reply Quote 0
        • D
          dasch last edited by

          maybe this can help you:
          https://www.backtrader.com/docu/commission-schemes/commission-schemes/
          https://www.backtrader.com/docu/sizers/sizers/

          1 Reply Last reply Reply Quote 0
          • D
            dasch @J T last edited by

            @J-T from your code examples, it is not clear what you are doing.

            in a strategy, you could do the following:

                        self.sizer = btoandav20.sizers.OandaV20Risk(risk_percents=2, stoploss=10)
                        print(self.sizer.getsizing(data=self.data0, isbuy=True))
            

            which will work, when data is a oanda feed

            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(); }); }