The problem isn't with order_target(stock, 0)
. The problem is really the line before.
The variable 'macd_raw' is a numpy array while 'macd_pre' is a float64 scaler. The logic condition in your if statement can't compare an array with a scaler.
Below is the original code...
# Close position for the stock when the MACD signal is negative and we own shares.
if macd_raw** < macd_pre and current_position > 0 and data.can_trade(stock):
order_target(stock, 0)
# Enter the position for the stock when the MACD signal is positive and
# our portfolio shares are 0.
elif macd_raw** > macd_pre and macd_pre < macd_raw[-3] and signal > signal_pre and current_position == 0 and data.can_trade(stock):
order_target_percent(stock, context.pct_per_stock)
Not sure what you are trying to do, but simply put an index on the 'macd_raw' array and it works (but maybe isn't what you wanted to do)? Now two scalers are being compared. Note this same error occurs in both conditions.
# Close position for the stock when the MACD signal is negative and we own shares.
if macd_raw[0] < macd_pre and current_position > 0 and data.can_trade(stock):
order_target(stock, 0)
# Enter the position for the stock when the MACD signal is positive and
# our portfolio shares are 0.
elif macd_raw[0] > macd_pre and macd_pre < macd_raw[-3] and signal > signal_pre and current_position == 0 and data.can_trade(stock):
order_target_percent(stock, context.pct_per_stock)