Hi,
I`m trying to programme my exit logic in algorithm. I want exit position when SimpleMovingAverage_10 > SimpleMovingAverage_30
Here is my syntax
def my_rebalance(context,data):
for stock in context.portfolio.positions:
SMA_10 = SimpleMovingAverage(inputs=[USEquityPricing.close],window_length=10,mask=stock)
SMA_30 = SimpleMovingAverage(inputs=[USEquityPricing.close],window_length=30,mask=stock)
bSell = SMA_10 > SMA_30
print('Sell stock: ' , bSell)
if bSell and data.can_trade(stock):
order_target_percent(stock,0)
When I print my variable bSell, which is supposed to be a boolean, output is:
PRINT ('SMA_10: ', NumExprFilter(expr='x_0 > x_1', bindings={'x_0': SimpleMovingAverage([close], 10), 'x_1': SimpleMovingAverage([close], 30)}))
How can I use bSell as boolean for exit position logic?
Thanks,
Michael