Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. cept0r
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    • Profile
    • Following 1
    • Followers 1
    • Topics 8
    • Posts 46
    • Best 5
    • Groups 0

    cept0r

    @cept0r

    5
    Reputation
    59
    Profile views
    46
    Posts
    1
    Followers
    1
    Following
    Joined Last Online

    cept0r Unfollow Follow

    Best posts made by cept0r

    • RE: Order execution confusion?

      Ahaa I think I got it now, I just needs to make sure each step only issues one limit order and go from there. Thank you.

      posted in Indicators/Strategies/Analyzers
      cept0r
      cept0r
    • RE: Unconverted data remains at .000 tried everything please help

      I solved it! instead of using

      GenericCSVData
      

      I used this instead;

      btc = pd.read_csv('/home/dev/PycharmProjects/Backtesting/csvdata/BTCUSDT-1m-data.csv',
                        index_col='timestamp',
                        parse_dates=True)
      
      
      feed = bt.feeds.PandasData(
          dataname=btc,
      
          fromdate=datetime.datetime(2020, 1, 1),
          todate=datetime.datetime(2020, 1, 2),
      
          timeframe=bt.TimeFrame.Minutes,
      
      

      Now it works! Sorry for wasting anybody's time.

      posted in General Code/Help
      cept0r
      cept0r
    • RE: Creating unique identifiers on my indicator.

      Solved it!
      After hours of trying different things I managed to solve it using this code:

          def __init__(self):
              self.ama = bt.indicators.AdaptiveMovingAverage(period=self.p.period,
                                                             fast=self.p.fast,
                                                             slow=self.p.slow,
                                                             plotname='AdaptiveMovingAverage',
                                                             color='yellow')
      
              #  Create upper & lower band 1
              self.l.top = self.ama * (1 + self.p.perc / 100)
              top = bt.LinePlotterIndicator(self.l.top, name='top', subplot=False)
              top.plotinfo.plotname = 'top'
      
              self.l.bot = self.ama * (1 - self.p.perc / 100)
              bot = bt.LinePlotterIndicator(self.l.bot, name='bot', subplot=False)
              bot.plotinfo.plotname = 'bot'
      
              #  Create upper & lower band 2
              self.l.top2 = self.ama * (1 + self.p.perc2 / 100)
              top2 = bt.LinePlotterIndicator(self.l.top2, name='top2', color='cyan', subplot=False)
              top2.plotinfo.plotname = 'top2'
      
              self.l.bot2 = self.ama * (1 - self.p.perc2 / 100)
              bot2 = bt.LinePlotterIndicator(self.l.bot2, name='bot2', color='cyan', subplot=False)
              bot2.plotinfo.plotname = 'bot2'
      
              #  Create upper & lower band 3
              self.l.top3 = self.ama * (1 + self.p.perc3 / 100)
              top2 = bt.LinePlotterIndicator(self.l.top3, name='top3', color='red', subplot=False)
              top2.plotinfo.plotname = 'top3'
      
              self.l.bot3 = self.ama * (1 - self.p.perc3 / 100)
              bot2 = bt.LinePlotterIndicator(self.l.bot3, name='bot3', color='red', subplot=False)
              bot2.plotinfo.plotname = 'bot3'
      
              #  Create upper & lower band 4
              self.l.top4 = self.ama * (1 + self.p.perc4 / 100)
              top2 = bt.LinePlotterIndicator(self.l.top4, name='top4', color='orange', subplot=False)
              top2.plotinfo.plotname = 'top4'
      
              self.l.bot4 = self.ama * (1 - self.p.perc4 / 100)
              bot2 = bt.LinePlotterIndicator(self.l.bot4, name='bot4', color='orange', subplot=False)
              bot2.plotinfo.plotname = 'bot4'
      
      posted in General Code/Help
      cept0r
      cept0r
    • RE: Issuing multiple orders, how do I only issue one order at a time?

      @run-out

              if pos == 0:
                  if close < mean:
                      self.buy(price=buy1, size=1, exectype=bt.Order.Limit)
                      self.log('Close below mean buying step 1... %.2f' % close)
              if close >= sell1 and pos > 0:
                  self.close()
                  self.log('Closing long... %.2f' % close)
      

      When I removed "self.long =" I managed to get some sells executed running this code, looks like I'm getting some more possible solutions.
      Trying them now..

      posted in General Code/Help
      cept0r
      cept0r
    • RE: Issuing multiple orders, how do I only issue one order at a time?

      Oh my bad, I'm not expecting any more buy orders to happen. I think I managed to solve it now and I understand what I'm doing wrong.
      Thank you @ab_trader and @run-out ! I'll keep at it

      posted in General Code/Help
      cept0r
      cept0r

    Latest posts made by cept0r

    • RE: Backtesting UI

      @OmegaUI-Trading
      Wow been looking for something like this! thanks for sharing.

      posted in General Discussion
      cept0r
      cept0r
    • RE: Backtrader's Future

      I'd love to be apart of the discord group as well!

      posted in General Discussion
      cept0r
      cept0r
    • RE: After stop-loss is executed stop algorithm for x amount of hours

      @run-out
      So I did not get the full picture of what you are trying to explain.

      This is what I got so far:

      self.t1 = close + datetime.timedelta(hours=4)
      

      Current close + 4hours stored in a variable

      Stop-loss:

              if pos == step4:  # 4
                  if close <= buy4:
                      self.stoploss = self.sell(price=stop, size=-pos, exectype=bt.Order.Stop)
                      self.log('Close below buy step 4.. creating stoploss @ %.2f' % stop)
                      print(pos)
                      if close >= sell1:
                          self.cancel(self.stoploss)
                          self.log('Current price reached sell 1 cancelling stop... %.2f' % close)
                          print(pos)
      

      Where do I place my "timer" variable so that if the stoploss executes the algorithm initiates the variable and stops the algorithm for x hours ?

      posted in General Code/Help
      cept0r
      cept0r
    • RE: After stop-loss is executed stop algorithm for x amount of hours

      @run-out Thank you!

      posted in General Code/Help
      cept0r
      cept0r
    • After stop-loss is executed stop algorithm for x amount of hours

      I was looking around on how to implement a timer so that every time I get stopped out I want to stop the strategy for x hours and start it up again once x hours has passed.
      What is a simple way to implement this?

      Let's say I have something like this:

      if not self.position:
          if buy_signal1:
               self.buy()
      
      if self.position:
          if sell_signal1:
                self.sell()
          if stop_signal:
                self.sell()
                if stop_signal:
                      [insert timer code here?]
      
      posted in General Code/Help
      cept0r
      cept0r
    • RE: Share my customized commission scheme for cryptocurrencies

      Thank you! I'm using it myself now, slightly better than the one I had before

      posted in General Discussion
      cept0r
      cept0r
    • RE: Issuing multiple orders, how do I only issue one order at a time?

      That did not take either.. hmm well if I use static sizes that could work temporarily if only just to see if I can manage to finish my trade logic today.

      posted in General Code/Help
      cept0r
      cept0r
    • RE: Issuing multiple orders, how do I only issue one order at a time?

      @ab_trader
      On another note:

              if pos == 0:
                  if close < mean:
                      self.long = self.buy(price=buy1, size=1, exectype=bt.Order.Limit)
                      self.log('Close below mean buying step 1... %.2f' % close)
      
              if pos > 0:
                  if close > mean:
                      self.short = self.sell(price=sell1, size=-1, exectype=bt.Order.Limit)
                      self.log('Closing long... %.2f' % close)
      
      

      This works.

              if pos == 0:
                  if close < mean:
                      self.long = self.buy(price=buy1, size=1, exectype=bt.Order.Limit)
                      self.log('Close below mean buying step 1... %.2f' % close)
      
                  if pos > 0:
                      if close > mean:
                          self.short = self.sell(price=sell1, size=-1, exectype=bt.Order.Limit)
                          self.log('Closing long... %.2f' % close)
      
      

      This does not.
      So I can't indent and the extra conditions won't matter since it won't work indented so I'm trying:

              orders = self.broker.get_orders_open()
              orders = list(orders)
      

      Then I'll do if orders == 1 and pos < size2 etc..

      posted in General Code/Help
      cept0r
      cept0r
    • RE: Issuing multiple orders, how do I only issue one order at a time?

      @ab_trader
      I'm trying to get this " not self.long / self.short " condition to execute as I need a third condition in my strategy in order for it to work properly. But When I run this:

              if pos == 0:
                  if close < mean:
                      self.long = self.buy(price=buy1, size=1, exectype=bt.Order.Limit)
                      self.log('Close below mean buying step 1... %.2f' % close)
                      if not self.long and pos > 0:
                          self.sell(price=sell1, size=-pos, exectype=bt.Order.Limit)
                          self.log('Buy order 1 hit creating sell order... %.2f' % close)
      

      Or

              if pos == 0:
                  if close < mean:
                      self.long = self.buy(price=buy1, size=1, exectype=bt.Order.Limit)
                      self.log('Close below mean buying step 1... %.2f' % close)
      
                  if pos > 0 and not self.long:
                      if close > mean:
                          self.short = self.sell(price=sell1, size=-1, exectype=bt.Order.Limit)
                          self.log('Closing long... %.2f' % close)
      

      It only executes the buy but it does not recognize the "not self.long" condition here is the output: (same for both)

      019-12-15, Close 7023.99, Mean 7045.62, Buy1 7033.64, Sell1 7057.60, Buy2 7014.62, Sell2 7076.62, Stop 6978.05
      2019-12-15, Close below mean buying step 1... 7023.99
      --------------------------------  NOTIFY ORDER  --------------------------------
      AutoOrderedDict() Order Completed
      2019-12-15, Status 4: Ref: 1, Size: 1, Price: 7033.64111
      Created: 2019-12-15 00:30:00 Price: 7033.641114933333 Size: 1
      --------------------------------------------------------------------------------
      2019-12-15, Close 7014.82, Mean 7043.32, Buy1 7031.35, Sell1 7055.29, Buy2 7012.33, Sell2 7074.31, Stop 6978.05
      2019-12-15, Close 7021.39, Mean 7041.74, Buy1 7029.77, Sell1 7053.71, Buy2 7010.75, Sell2 7072.72, Stop 6978.05
      2019-12-15, Close 7016.95, Mean 7039.94, Buy1 7027.97, Sell1 7051.90, Buy2 7008.96, Sell2 7070.91, Stop 6978.05
      2019-12-15, Close 7020.44, Mean 7038.95, Buy1 7026.98, Sell1 7050.91, Buy2 7007.98, Sell2 7069.92, Stop 6978.05
      2019-12-15, Close 7021.28, Mean 7037.46, Buy1 7025.49, Sell1 7049.42, Buy2 7006.49, Sell2 7068.42, Stop 6978.05
      2019-12-15, Close 7037.76, Mean 7037.47, Buy1 7025.50, Sell1 7049.43, Buy2 7006.50, Sell2 7068.43, Stop 6978.05
      2019-12-15, Close 7037.51, Mean 7037.47, Buy1 7025.50, Sell1 7049.43, Buy2 7006.50, Sell2 7068.43, Stop 6978.05
      2019-12-15, Close 7035.25, Mean 7037.42, Buy1 7025.46, Sell1 7049.39, Buy2 7006.46, Sell2 7068.39, Stop 6978.05
      2019-12-15, Close 7038.30, Mean 7037.44, Buy1 7025.47, Sell1 7049.40, Buy2 7006.47, Sell2 7068.40, Stop 6978.05
      2019-12-15, Close 7038.36, Mean 7037.44, Buy1 7025.48, Sell1 7049.41, Buy2 7006.48, Sell2 7068.41, Stop 6978.05
      2019-12-15, Close 7030.42, Mean 7037.20, Buy1 7025.23, Sell1 7049.16, Buy2 7006.23, Sell2 7068.16, Stop 6978.05
      2019-12-15, Close 7027.24, Mean 7036.78, Buy1 7024.81, Sell1 7048.74, Buy2 7005.81, Sell2 7067.74, Stop 6978.05
      2019-12-15, Close 7032.76, Mean 7036.66, Buy1 7024.70, Sell1 7048.62, Buy2 7005.70, Sell2 7067.62, Stop 6978.05
      2019-12-15, Close 7040.45, Mean 7036.69, Buy1 7024.73, Sell1 7048.66, Buy2 7005.73, Sell2 7067.66, Stop 6978.05
      2019-12-15, Close 7047.92, Mean 7036.74, Buy1 7024.78, Sell1 7048.71, Buy2 7005.78, Sell2 7067.70, Stop 6978.05
      2019-12-15, Close 7044.39, Mean 7036.78, Buy1 7024.82, Sell1 7048.75, Buy2 7005.82, Sell2 7067.75, Stop 6978.05
      2019-12-15, Close 7043.37, Mean 7036.82, Buy1 7024.85, Sell1 7048.78, Buy2 7005.85, Sell2 7067.78, Stop 6978.05
      2019-12-15, Close 7047.54, Mean 7036.89, Buy1 7024.93, Sell1 7048.85, Buy2 7005.93, Sell2 7067.85, Stop 6978.05
      2019-12-15, Close 7044.09, Mean 7036.92, Buy1 7024.96, Sell1 7048.89, Buy2 7005.96, Sell2 7067.89, Stop 6978.05
      2019-12-15, Close 7038.41, Mean 7036.93, Buy1 7024.97, Sell1 7048.90, Buy2 7005.97, Sell2 7067.90, Stop 6978.05
      2019-12-15, Close 7042.26, Mean 7036.98, Buy1 7025.01, Sell1 7048.94, Buy2 7006.02, Sell2 7067.94, Stop 6978.05
      2019-12-15, Close 7039.05, Mean 7036.99, Buy1 7025.03, Sell1 7048.95, Buy2 7006.03, Sell2 7067.95, Stop 6978.05
      2019-12-15, Close 7042.52, Mean 7037.02, Buy1 7025.05, Sell1 7048.98, Buy2 7006.05, Sell2 7067.98, Stop 6978.05
      2019-12-15, Close 7037.30, Mean 7037.02, Buy1 7025.06, Sell1 7048.98, Buy2 7006.06, Sell2 7067.98, Stop 6978.05
      2019-12-15, Close 7034.75, Mean 7037.01, Buy1 7025.04, Sell1 7048.97, Buy2 7006.04, Sell2 7067.97, Stop 6978.05
      2019-12-15, Close 7036.46, Mean 7037.00, Buy1 7025.04, Sell1 7048.97, Buy2 7006.04, Sell2 7067.97, Stop 6978.05
      2019-12-15, Close 7037.07, Mean 7037.01, Buy1 7025.04, Sell1 7048.97, Buy2 7006.04, Sell2 7067.97, Stop 6978.05
      2019-12-15, Close 7042.83, Mean 7037.09, Buy1 7025.12, Sell1 7049.05, Buy2 7006.12, Sell2 7068.05, Stop 6978.05
      2019-12-15, Close 7046.28, Mean 7037.26, Buy1 7025.29, Sell1 7049.22, Buy2 7006.29, Sell2 7068.22, Stop 6978.05
      2019-12-15, Close 7041.87, Mean 7037.35, Buy1 7025.39, Sell1 7049.32, Buy2 7006.39, Sell2 7068.32, Stop 6978.05
      2019-12-15, Close 7043.00, Mean 7037.59, Buy1 7025.62, Sell1 7049.55, Buy2 7006.62, Sell2 7068.55, Stop 6978.05
      2019-12-15, Close 7044.89, Mean 7037.84, Buy1 7025.87, Sell1 7049.80, Buy2 7006.87, Sell2 7068.80, Stop 6978.05
      2019-12-15, Close 7048.59, Mean 7038.39, Buy1 7026.43, Sell1 7050.36, Buy2 7007.42, Sell2 7069.36, Stop 6978.05
      2019-12-15, Close 7052.48, Mean 7039.13, Buy1 7027.16, Sell1 7051.10, Buy2 7008.16, Sell2 7070.10, Stop 6978.05
      
      

      At the end closing price reaches sell1 so it should execute but it won't even create a sell order. So I'm wondering what I'm doing wrong?

      posted in General Code/Help
      cept0r
      cept0r
    • RE: Issuing multiple orders, how do I only issue one order at a time?

      Oh my bad, I'm not expecting any more buy orders to happen. I think I managed to solve it now and I understand what I'm doing wrong.
      Thank you @ab_trader and @run-out ! I'll keep at it

      posted in General Code/Help
      cept0r
      cept0r