Hello, I have been trying to write this ADX trading strategy for a course I am taking but since I am not a programmer , I am not able to correct my mistake . Can someone please check the below algorithm and maybe show me how to correct it ?
The following error is in the last part of the algo (from if function onwards) : ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
import talib
def initialize(context):
schedule_function(record_ADX, date_rules.every_day(), time_rules.market_close())
def record_ADX(context, data):
context.security = sid(5061)
period = 14
H = data.history(context.security,'high', 2*period, '1d').dropna()
L = data.history(context.security,'low', 2*period, '1d').dropna()
C = data.history(context.security,'price', 2*period, '1d').dropna()
ta_ADX = talib.ADX(H, L, C, period)
ta_nDI = talib.MINUS_DI(H, L, C, period)
ta_pDI = talib.PLUS_DI(H, L, C, period)
if (ta_ADX> 20) and (ta_nDI > ta_pDI):
order_target_percent(context.security, -1)
elif (ta_ADX>20) and (ta_nDI < ta_pDI):
order_target_percent(context.security, 1)