Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Limit / stop orders for short selling

Want to make sure how limit / stop order works in case of short sells.

I am using a construct like:

order_target_percent(stock, short_weight, limit_price=data.current(stock,'price')x0.95, stop_price=data.current(stock,'price')x1.1)

The way I interpret this is
1. Purchase stock as it goes down but not further than 5% lower than target price
2. If it goes up 10% over the target price, sell at market

Is that the right way to think about it?

5 responses

Vladimir,
The order you coded does not do what you want.

The order will place a limit order when the stock price hits 1.1 X the price when the order is sent.
The order will try to fill at any price that is below .95 X the price when the order is sent.

As an example for a buy order:
Price when order is issued: $100.00 (stop/limit order is created, no trades)
Limit order will be created when price reaches $110.00. (purchase limit order is triggered, no trades until price < limit price)
The order will purchase the short_weight amount at any price that is below $95.00, but not above $95.00.
SEC Definition of Stop-Limit Order

Best,
Cory

Updated track_orders for StopLimit orders. You can use this tool to see what's happening.

2016-01-14 06:31 _orders:65 INFO    1   Sell -1 SPY now 189.67 stop 189.63 limit 191.19 cash 1000  2c31  
2016-01-14 07:36 _orders:65 INFO   66      Sold -1 SPY limit at 191.24   cash 1190  2c31  
2016-01-15 06:31 _orders:65 INFO    1   Sell -1 SPY now 186.80 stop 186.75 limit 188.29 cash 1190  ea33  
2016-01-15 13:00 WARN Your order for -1 shares of SPY failed to fill by the end of day and was canceled.  
2016-01-19 06:31 _orders:65 INFO    1    Canceled Sell -1 SPY limit at 189.95  
2016-01-19 06:31 _orders:65 INFO    1   Sell -1 SPY now 189.95 stop 189.91 limit 191.47 cash 1190  3781  
2016-01-19 13:00 WARN Your order for -1 shares of SPY failed to fill by the end of day and was canceled.  
2016-01-20 06:31 _orders:65 INFO    1    Canceled Sell -1 SPY limit at 185.13  
2016-01-20 06:31 _orders:65 INFO    1   Sell -1 SPY now 185.13 stop 185.09 limit 186.62 cash 1190  ed1b  
2016-01-20 12:21 _orders:65 INFO  351      Sold -1 SPY limit at 187.00   cash 1376  ed1b  
2016-01-21 06:31 _orders:65 INFO    1   Sell -1 SPY now 185.82 stop 185.78 limit 187.31 cash 1376  c6dd  
2016-01-21 07:21 _orders:65 INFO   51      Sold -1 SPY limit at 187.32   cash 1562  c6dd  

Thanks, very helpful in understanding what happens.

You're welcome.

Meanwhile there's an optional further step one could do, with stoplimit orders. When stop is reached, the order is converted to a limit order by removing the stop price. If stop_reached were set to True instead, then when filled it would be easy to log them as stoplimit orders rather than just as limit orders as you see above.

Imagine a strategy where any type of order might be used. It could be useful to see which fills were stoplimit distinguishable from those entered as purely limit orders.

The extra step would be to watch stoplimit orders every minute for when status remains 0 while stop price disappears (stop reached, can then also log that point), store that id, until their limit is reached and when complete, see if it is on the list of stored id's and log them as stoplimit instead of just limit, and then remove them from the stoplimit watch list. Just extra processing and code complexity.

This stoplimit order from open to filled happened to be selling 1 share ...

I'm having a similar problem. I'm putting an order to enter a short position, and I want it to execute at a bit under market price or higher. setting the limit_order field to that price makes the algorithm sell at that price or lower.
Is there a thing like an opposite limit price or something? I feel like the answer should be on this page.