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)

Clone Algorithm
9
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5a12c7319c762d4132ff1bc9
There was a runtime error.
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.