Hey guys, Got a pretty simple question about how to implement public properties within the Order class. https://www.quantconnect.com/terminal/docs/topic655.html Id like to set the trailing stop, set the stop loss, and take profit at a certain price/percentage. I searched the forums but didn't find anything directly related. Thanks! Best, -Travis
Levitikon
Hey Travis. After spending a couple minutes looking into it I don't think you're going to be able to use those properties. While looking around in Lean, I was able to track usages of classes in that namespace to a pretty interesting possibly alternative, or legacy way, or behind the scenes way of conducting orders. In the InteractiveBrokersBrokerageTests class (https://github.com/QuantConnect/Lean/blob/master/Tests/Brokerages/InteractiveBrokers/InteractiveBrokersBrokerageTests.cs) on line 218 you see an order is created and on line 220 the order is placed using a InteractiveBrokersBrokerage object. The order created on line 218 is what contains the properties you seek. But the problem is all of these objects are part of the QuantConnect.Brokerages project (Assembly) that is not referenced from QuantConnect.Algorithm.CSharp project so it's out of reach for Algorithms. Maybe someone else can better help with the trailing stop stuff, but I did see a pretty neat trailing stop implementation by Nik in this post here. The second shared algo has a file called TrailingStop.cs that might help you out: https://www.quantconnect.com/forum/discussion/614/vxx-intraday-strategies/p1
Stephen Oehler
Yeah after looking around in this myself, I kept coming to the conclusion that you may need to implement a custom brokerage model to get these to work in the way you're intending.
Michael Handschuh
Stop loss orders are supported via the StopMarketOrder and StopLimitOrder order types. As for the trailing stop, this is not currently natively supported. The current recommend approach is to update your StopMarketOrder or StopLimitOrder with a new stop price that 'trails' the current market price by some defined amount. Take a look at the attached example. I've also plotted the stop price against the SPY price so you can see how it gets updated and finally executes when the two lines cross.
Travis Teichelmann
Thanks for all your answers guys. Seems like Micheal has the perfect algorithm for this. In previous efforts to implement trailing stop orders, I had trouble recording the current price and storing it to a variable. In python I could append the current value to something but you seem to have taken care of that with the variables currentStopLoss and newStopLoss. Thanks again
Travis Teichelmann
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.
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!