LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
Sorry for asking about such stupid questions but i am getting frustrated with the Stop Limit Order Function.
I expected that the Order is submitted to the ticker and closes automatically when it reaches the stop loss or take profit limit.
I thought that this simple Line of Code do the job but as u can see in the backtest it wont...
var stopLimitTicket = StopLimitOrder(contract.Symbol, 10, (decimal)stopPrice, (decimal)limitPrice);Can someone please fix my code that the open Position close automatically when it reaches the limits? I don't want to destroy my computer today because I'm angry... Thanks in forward.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Rahul Chowdhury
39.9k Pro
,
Hey Pierre,
Sorry it has been so frustrating. I think the problem may be a misunderstanding of how StopLimitOrder works. StopLimitOrder doesn't set both a stop loss and a take profit, it only sets 1 order. A long StopLimitOrder waits until the price has fallen below the stop price and then sets 1 limit order at the limit price.
To implement a stop loss and a take profit, you must set 2 separate exit orders, along with your entry order.
// entry
var marketOrderTicket = MarketOrder(contract.Symbol, 10)
// stop loss
var stopLossTicket = StopMarketOrder(contract.Symbol, -10, stopPrice)
// take profit
var takeProfitTicket = LimitOrder(contract.Symbol, -10, limitPrice)
Keep in mind if either your stop loss or your take profit is filled, you must cancel the other exit order or you may end up in a net short position if both are filled. You can handle order cancellations with the order tickets.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Loading...
To unlock posting to the community forums please complete at least 30% of Boot Camp. You can
continue your Boot Camp training progress from the terminal. We
hope to see you in the community soon!