Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Problem placing a stop order

For some context, this is a block of code that's executed at the start of the trading day, 2 minutes after the market open:

tStop['perc'] = context.baseNATR*context.positionInfo['finalScore'][pos]*context.natrs[pos]/context.shortLongRatio  
tStop['peg'] = context.portfolio.positions[pos].last_sale_price  
trigger =  tStop['peg']*(1-tStop['perc']/100)  
log.info('Placing trailing stop on LONG {}, perc: {}%'.format(pos,tStop['perc']));  
tStop['order'] = order_target(pos,0,StopOrder(trigger))  

This will ultimately be a simulated trailing stop, however, it fails on the last line with the error:

Attempted to place an order with a limit price of .

Up to this point I've confirmed the security is long in the portfolio, that trigger is a positive number and less than the last known price. If I remove the StopOrder directive I can place the order, however if I change the order to plain order (i.e. order(pos,0,StopOrder(trigger)) it gives the same error. Any thoughts on what the deal is?

2 responses

Nevermind, found it, added "style=", I suppose there are some unpublished arguments for the order function.

That's right, to place a non-market order, you'll need to use the style parameter. Here is the documentation for more info: https://www.quantopian.com/help#ide-ordering

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.