Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Trouble with rebuilding a squeeze momentum indicator

Hey,
we have to work with Quantopian for a seminar at university. Our next task was to rebuild a squeeze momentum indicator using Bollinger Bands and Keltner Channels. My goal was to combine this with the Directional Movement Indicator as a signal for the direction of the next trade. But unfortunately I stuck at the ordering part. I don't know how to implement the order correctly (order if BB are within KC; direction depends on DI+ and DI-). Maybe I just use a wrong intuition due to my limited experience with python (I only used R and Matlab so far).
I will attach the algo. For any help or comments I am very thankful.

If you run the code, you will see that the following runtime error occurs:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
USER ALGORITHM:46, in trend_signal
sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)

2 responses

Florian,

Try something like this:

    sqzOn = (lowerBB[-1] > lowerKC[-1]) and (upperBB[-1] < upperKC[-1])  
    sqzOff = (lowerBB[-1] < lowerKC[-1]) and (upperBB[-1] > upperKC[-1])    

    DIp = talib.PLUS_DI(high, low, prices, 20)[-1]  
    DIm = talib.MINUS_DI(high, low, prices, 20)[-1]  

and change initial capital.

Thank you Vladimir. It worked.