Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Stop-loss and limit orders

I am having difficulty understanding the way one should use stop-loss and limit orders in the Quantopian environment.

For example, if the following order is placed,

p = data[stock].price
order(stock, 100, style=StopLimitOrder(limit_price = p*1.05, stop_price = p*0.99 )) ,

am I interpreting this correctly as 100 shares being bought immediately (market order) and then being automatically sold off if the price drops below 99% per-cent (to stop the loss) of the current price or rises above 105% of the current price (to collect profit)?

Regards,

Tim

3 responses

Tim, any given order command places only one order. If you want to both place an order to open a position, and place a stop-loss order to close the position, then you need to do that in two different commands.

What you're doing with the example you posted is place a single stop-limit order. (I find that investopedia link to be very helpful)

more help here

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thanks Dan!

I still think that the type of order I envisaged above might be useful. :-)

Hey guys , I'm confused while implementing stop loss ,any help in this way would be really great .

I tried implementing stoploss in handle_data() function as it samples data each minute and verifies if our stop conditions are satisfied.I'm using rebalance() function to place orders on a daily basis using custom weights.My doubt is before placing orders in rebalance() should I check for open orders and then place ?

I'm a bit confused here because the ordering is taking place both in handle_data() when checking for stop-loss condition and in rebalance() as in regular ordering.