3 Consecutive Highs / Low?
-
I was doing peak detection but I just realized BT has a wide array of indicators that I am not too 100% familiar with.
Is there an indicator that determines 3 consecutive highs (each higher than the previous)..?
-
There is no such thing, but
bt.All(high > high(-1), high(-1) > high(-2), high(-2) > high(-3))
(orAnd
if you prefer) should do the trick. -
now that's elegant..
thank you -
You may alternatively pack it in an indicator, which will allow you to decide how many highs to consider by means of a parameter
This is untested, but the general idea should be something like it.
class ConsecutiveIncreases(bt.Indicator): lines = ('consecutive',) params = ( ('period', 3), # how many to consider ('ago', 0), # offset to start in the past ) def __init__(self): incs = [self.data(-i) < self.data(-i - 1) for i in range(self.p.ago, self.p.ago + self.p.period)] self.lines.consecutive = bt.All(*incs)
Which you can later use with any of the defined fields of a data feed
o5 = ConsecutiveIncreases(self.data.open, period=5) # 5 consecutive higher opens h5 = ConsecutiveIncreases(self.data.high) # 3 consecutive higher highs
Of course the indicator can be directly specialized to use
self.data.high
rather than the genericself.data
-
Will test it out. Thanks once again