Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Stop Orders not going through

Hi all,

I can't seem to figure out how to create a successful stop order for the life of me. I've searched the forums and reviewed Jacob's post with the suggestions there but I still can't seem to get it.

I've attached some very basic test code that I would think would execute a stop order at the correct prices, but as you can see from the logs and the recorded shares & price graph, it's not. Any ideas?

4 responses

James, I think your orders are going through just fine. I think that you're having some stop-order confusion, which is understandable. They mess with my head too.

A stop order is also known as a stop-loss order. There's a lengthy explanation on investopedia with a key line: "With a stop-loss order for a long position, a market order to sell is triggered when the stock trades below a certain price, and it will be sold at the next available price."

In your case, you're placing a stop order, that is a sell order, at a price that is above the current market price. That sell stop order is placed, the market price is lower than the stop, so the order is converted to a market order, and it executes immediately.

Once I unraveled that, I think I found a few more logical errors in your algo. You can see if you agree with my changes below.

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.

Ahh that helps a great deal!

So what I was really looking to do then was set a Take Profit, not a Stop Loss. In that case, would I want to use a limit order to accomplish that?

Yes, that's what you're looking for. You may need to revert some of the changes I made to your code because I was working with a bad assumption.

Okay sounds great, thanks for your help!