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/

    recursive indicators

    Indicators/Strategies/Analyzers
    2
    4
    213
    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.
    • V
      vaclavku last edited by

      Hello community,
      it seems a little bit confusing for me if the method nextstart() still needs to be used as written here:
      https://medium.com/@danjrod/custom-recursive-indicator-in-python-with-backtrader-1878959ec011

      I've created a simple PnL indicator:
      class MyReturn(bt.Indicator):

      lines = ('rtn',)
      params = (('loopback', 30),)
      
      def __init__(self):
          self.lines.rtn = self.data(0)/ self.data(-self.params.loopback) - 1
      

      And surprisingly it works as excepted with nextstart. Any positive externality from my end, or the library is already involving this?

      Last, may I kindly ask you about one point where I'm almost lost:
      Is there a method that would count the number of bars between the self.data(0) and the buy where the order was executed?

      Many thanks,
      vaclav

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        1. At the top of each page
        For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
        
        1. You have NOT developed a recursive indicator, because you don't use the previous output of your own calculations.

        2. That thing does already exist, it is called PercentageChange (I do understand that the point was to create do it yourself)

        1 Reply Last reply Reply Quote 2
        • V
          vaclavku last edited by backtrader

          Hello, very appreciated. Thank you to help me understand both raised topics as well as the rules (sorry for that).
          However, I was misunderstood in the second topic. I'd like to use sumN, however I can't find the actual parameter of order.
          My interest is to dynamically update the params period. I'd like to use 4 if I'm 4 bars after the order is being accepted or 10 in the order was accepted in [-10] etc.
          """2018-05-15, BUY EXECUTED, Price: 82.45, Cost: 824.50, Comm 0.00, BARS 1.00
          2018-05-15, Close: 81.32, XYZ: -0.11
          2018-05-16, Close: 81.67, XYZ: -0.11
          2018-05-17, Close: 82.50, XYZ: -0.10"""

          I'd like to see the no of bars for 2018-05-15 = BARS 2.00, 2018-05-16 = BARS 3.00...
          Is that possible?

          1 Reply Last reply Reply Quote 0
          • V
            vaclavku last edited by

            Please, disregard the last question and don't lose time with it. I've finally found the information in the quick start (self.bars_executed).

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