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



  • 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('--------------------')
    


  • @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.



  • @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 ?



  • 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


Log in to reply
 

});