I have a fairly simple strategy with a signal. i.e. If 'signal' > 0.05, then short two specified stocks with specified weights. This will run once a day.
def handle_data(context, data): .... if signal > 0.05: if SPY not in open_orders and AAPLnot in open_orders: order_percent(SPY, -0.01) order_percent(AAPL, -0.01)
So if the 'signal' is > 0.05 for 4 days in a row, this means that the trades will have occurred 4 times.
I'm trying to figure out how to close the trades given a condition is met. e.g.
- If a trade has been open for 10 days, close that trade.
- If a trade has gained more than x%