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/

    Sell nextday openprice

    General Code/Help
    2
    2
    19
    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.
    • W
      wnwkr13 last edited by

      hello, I am trying to make voltalitybreakout strategy. My strategy is like buy stocks when Target price( yesterday (highprice - lowprice) * 0.5 ) is lower than today's HIGH price, then sell next day on next_price. But I have problem with Next open price, and I also would like to know to figure out the custom size. I mean this is multi-data on single strategy. If I want to trade maximum 10% of my total budget on each stock, How can I figure it out?

      def __init__(self):
          self.inds = dict()
          for i, d in enumerate(self.datas):
              self.inds[d] = dict()
              self.inds[d]['OPEN'] =  self.datas[0].open
              self.inds[d]['HIGH'] = self.datas[0].high
              self.inds[d]['LOW'] = self.datas[0].low
              self.inds[d]['CLOSE'] = self.datas[0].close
              self.inds[d]['PAYMENT_VOLUME'] = self.datas[0].PAYMENT_VOLUME
              self.inds[d]['RANGE'] = self.datas[0].high - self.datas[0].low
              self.inds[d]['TARGET'] = self.datas[0].open + self.inds[d]['RANGE'](-1)*0.5
              self.inds[d]['NextOpen'] = self.datas[0].open(1)
      
      
      
      def next(self):
          for i, d in enumerate(self.datas):
              # dt, dn = self.datetime.date(d), d._name
              pos = self.getposition(d).size
      
              if not pos:
                  if self.inds[d]['TARGET'][0] < self.inds[d]['HIGH']:
      
                      #Calculate the max number of shares ('all in')
                      # size = int(self.broker.getcash() / self.datas[0].open) - 1 ##
                      self.buy(data=d, size=100000)
                  elif self.inds[d]['NextOpen']:
      
                      self.sell(data=d, size=100000)
              else:
                  if self.inds[d]['TARGET'][0] < self.inds[d]['HIGH']:
                      self.close(data=d)
                      # Calculate the max number of shares ('all in')
                      # size = int(self.broker.getcash() / self.datas[0].open) - 1 ##
                      self.buy(data=d, size=100000)
                  elif self.inds[d]['NextOpen']:
                      self.close(data=d)
                      self.sell(data=d, size=100000)
                      # self.sell(data=d, size=self.position.size)
      run-out 1 Reply Last reply Reply Quote 0
      • run-out
        run-out @wnwkr13 last edited by

        @wnwkr13 Yes you have a few issues going on.

        @wnwkr13 said in Sell nextday openprice:

        self.inds[d]['HIGH']

        This is not a valid line in next. This is a full line and in next you need to grab usually the current bar. So would be:

        self.inds[d]['HIGH'][0]
        

        @wnwkr13 said in Sell nextday openprice:

        self.inds[d]['NextOpen'] = self.datas[0].open(1)

        This is not a viable line eit5her. You can never look forward into next except on specific methods. Follow cheat-on-open as a guide.

        1 Reply Last reply Reply Quote 2
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }