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/

    Lowest indicator issue

    General Code/Help
    2
    4
    51
    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.
    • B
      balibou last edited by

      I use the Lowest indicator.
      I try to compare my bollinger bandwith value with the minimum one on a specific period (60).
      Unfortunately the minimum one is always equal to my bollinger bandwith value calculated.

      Any thoughts ?

      class BaseStrategy(bt.Strategy):
          def __init__(self):
            self.bbw = bt.indicators.BollingerBandsPct()
      
          def next(self):
            print('--------------------')
            bbw = (self.bbw.top - self.bbw.bot) / self.bbw.mid
            minbbw = min(bbw, 60)
            print(bbw == minbbw) # alway True
            print('--------------------')
      
      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        @balibou said in Lowest indicator issue:

        I use the Lowest indicator.

        No, you don't use it in the script shown.

        I try to compare my bollinger bandwith value with the minimum one on a specific period (60).

        In your script you compare your bbw with 60.

        1 Reply Last reply Reply Quote 1
        • B
          balibou last edited by

          @ab_trader in the documentation it is explained that it calculates the lowest value for the data in a given period:

          • lowest = min(data, period)

          To me I assumed (and was mistaken as you said):

          • that data is the bbw indicator
          • period is the last 60 candles

          So if I'm right, I should:

          • create an array with the last 60 bbw values (bbwArray)
          • find the minimum in the array
          • compare this minmum with bbw[0]
          bbw = (self.bbw.top - self.bbw.bot) / self.bbw.mid
          minbbw = min(bbwArray, 60)
          print(bbw == minbbw)
          

          Right ?

          1 Reply Last reply Reply Quote 0
          • B
            balibou last edited by

            ok finally I went for a good old method:

            print('--------------------')
            # calculating bbw
            bbw = (self.bbw.top - self.bbw.bot) / self.bbw.mid
            # listing last 20 bbw
            result_t = [self.calculateBBW(k) for k in range(-20, 0)]
            # filtering nan value in the list
            minbbw = 0 if math.isnan(min(result_t)) else min(result_t)
            # comparing values
            print(bbw <= minbbw)
            print('--------------------')
            

            I really struggle sometimes to understand the documentation when there are no examples

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