If I short a stock I would like to place a Buy-Stop order so that I cover the position if the price goes up by a specified amount. Can I do this with the available order types in Quantopian?
I assume I'm doing something wrong as this
order(Sid, 1, limit_price=data[Sid].close_price * 1000) # 1000 chosen for emphasis only!
executes at the next bar irrespective of price i.e.
Code (plus some code not shown to print the order the next day):
print data[Sid].close_price
orderid = order(Sid, 1, limit_price=data[Sid].close_price * 1000)
print get_order(orderid)
Log:
2003-01-08PRINT26.99
2003-01-08PRINTEvent({'status': 0, 'created': datetime.datetime(2003, 1, 8, 0, 0,
tzinfo=<UTC>), 'limit_reached': False, 'stop': None, 'stop_reached': False,
'amount': 1, 'limit': 26990.0, 'sid': Security(122, symbol=u'ADI',
security_name=u'ANALOG DEVICES INC', start_date=datetime.datetime(1993, 1, 4, 5, 0,
tzinfo=<UTC>), end_date=datetime.datetime(2013, 10, 14, 5, 0,
tzinfo=<UTC>), first_traded=None), 'dt': datetime.datetime(2003, 1, 8, 0, 0,
tzinfo=<UTC>), 'id': '1490d0770614414dbec8ab0c5063d3a4', 'filled': 0})
2003-01-09PRINTEvent({'status': 1, 'created': datetime.datetime(2003, 1, 8, 0, 0,
tzinfo=<UTC>), 'limit_reached': True, 'stop': None, 'stop_reached': False, 'amount': 1,
'limit': 26990.0, 'sid': Security(122, symbol=u'ADI',
security_name=u'ANALOG DEVICES INC', start_date=datetime.datetime(1993, 1, 4, 5, 0,
tzinfo=<UTC>), end_date=datetime.datetime(2013, 10, 14, 5, 0,
tzinfo=<UTC>), first_traded=None), 'dt': datetime.datetime(2003, 1, 9, 0, 0,
tzinfo=<UTC>), 'id': '1490d0770614414dbec8ab0c5063d3a4', 'filled': 1})
Transaction:
2003-01-09 00:00:00 ADI BUY 1 $28.37 $28.37
P.