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/

    signals stop showing after a certain date

    General Code/Help
    2
    3
    123
    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.
    • K
      kicgahi last edited by

      pretty new to this. followed some guide online and i managed to write out this code which seems to work fine until after july. I'm just trying to create a chart with the 14 day RSI as an indicator to signal buy (rsi<30) and sell (rsi>70) points.

      here is my code

      import backtrader as bt
      import datetime
      
      class RSIStrategy(bt.Strategy):
      
          def __init__(self):
              self.rsi = bt.talib.RSI(self.data, period=14)
      
          def next(self):
              if self.rsi < 30 and not self.position:
                  self.buy(size=1)
              
              if self.rsi > 70 and self.position:
                  self.close()
      
      
      cerebro = bt.Cerebro()
      
      fromdate = datetime.datetime.strptime('2020-01-01', '%Y-%m-%d')
      todate = datetime.datetime.strptime('2020-12-25', '%Y-%m-%d')
      
      data = bt.feeds.GenericCSVData(dataname='2020_hourly.csv', dtformat=2, compression=60, timeframe=bt.TimeFrame.Minutes, fromdate=fromdate, todate=todate)
      
      cerebro.adddata(data)
      
      cerebro.addstrategy(RSIStrategy)
      
      cerebro.run()
      
      cerebro.plot()
      

      the data import is fine, double checked that so it shouldn't be the problem. but the chart it produces looks like this

      Screenshot 2020-12-28 at 3.31.23 AM.jpg

      as you can see, after around end july, the signals stop appearing even though there are certain points where the rsi is clearly below 30 (some even below 20) or over 70.

      could anyone help identify what the problem is? would really appreciate it, thanks!

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        Most probably this is because of the available cash that you set for the broker - actually you didn't so the default (10000$) is used instead. The problem is that the price of the asset you are working with grows beyond that limit - the price is already around 11000$ after July. So your orders are simply rejected from that point on.

        Try to set the available cash to something larger:

        cerebro.broker.setcash(1000000)
        
        K 1 Reply Last reply Reply Quote 3
        • K
          kicgahi @vladisld last edited by

          @vladisld said in signals stop showing after a certain date:

          cerebro.broker.setcash(1000000)

          thanks for the help, it does work now!

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