Hi,
I'm interested in how to take indicator such as Simple moving average, RSI or EMA etc. and feed into them stock from context.portfolio.positions. Simply take Dictionary: A dictionary of all the open positions, keyed by security ID. Convert them to array and use this in for loop to value all open positions. I want to used it in my algorithm for exiting positions. I tried this code, but doesn't works and I don't know why...
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)
Thanks,
Michael