Navigation

    Backtrader Community

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

    sspy

    @sspy

    0
    Reputation
    108
    Profile views
    6
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    sspy Unfollow Follow

    Latest posts made by sspy

    • RE: Bar data N days back

      I was able to find a solution,

      self.data.close.get(size=1, ago=-1)[0]
      

      works right as I want

      posted in General Code/Help
      S
      sspy
    • RE: Bar data N days back

      @backtrader said in Bar data N days back:

      It would seem you are unaware of the Python arithmetic with arrays.

      I understand the python arrays but this logic is unacceptable here, because we can't get future data, so the -1 has to be the previous day, -2 the day before it and so on and if no such day is available to throw an exception, but not start everything in a circle.

      @backtrader said in Bar data N days back:

      Using a delayed index provides the proper automatic constraint to the platform.

      Can you show me an example of proper way to get data for 2 days back or exeption if no such data is available?

      posted in General Code/Help
      S
      sspy
    • RE: Bar data N days back

      I'm completely confused. Is there a simple way to get data N days back?

      posted in General Code/Help
      S
      sspy
    • RE: Bar data N days back

      @backtrader said in Bar data N days back:

      You are simply doing things wrong. But you can disable preloading: Docs - Cerebro

      Thank you for your prompt reply. Finally I was able to get it right.

      The only moment by disabling preloading I was able to get

      next:: current period: 1
      date 2018-01-01 23:59:59.999989, current price 50.10, previous price 50.10
      

      it's certainly better, but still not how it should

      posted in General Code/Help
      S
      sspy
    • RE: Bar data N days back

      @backtrader said in Bar data N days back:

      Because the data is preloaded

      Can this behavior be disabled? It really confuses me.

      posted in General Code/Help
      S
      sspy
    • Bar data N days back

      I want to access the data N days ago. I have written the following code

          def next(self):
              print('next:: current period:', len(self))
              print('date %s, current price %.2f, previous price %.2f' % (self.datas[0].datetime.datetime(), self.data.close[0], self.data.close[-1]))
      

      the dataset I use consists of 3 lines

      2018-01-01,50.1,...
      2018-01-02,50.2,...
      2018-01-03,50.3,...
      

      and the output is

      next:: current period: 1
      date 2018-01-01 23:59:59.999989, current price 50.10, previous price 50.30
      next:: current period: 2
      date 2018-01-02 23:59:59.999989, current price 50.20, previous price 50.10
      next:: current period: 3
      date 2018-01-03 23:59:59.999989, current price 50.30, previous price 50.20
      

      How can day 1 previous price be 50.30? Why it takes the value of the last day and doesn't throws an error?

      posted in General Code/Help
      S
      sspy