Back

Implementing Trailing Stop Loss

I'm trying to translate an algorithm I wrote in MultiCharts/Tradestation's Power/EasyLanguage into C#. I'm new to C# and coding in general, so this has proved rather difficult, but I'm pretty close to done now. The last remaining issue I have is I need to implement a trailing stop that functions in the same way that PercentTrailing works: 

https://www.multicharts.com/trading-software/index.php/SetPercentTrailing

I take it I need to calculate the maximum profit somehow, but due to my inexperience with C# I'm not sure how I'd go about doing this. I also noticed that in the documentation there is a TrailingStop Field: https://www.quantconnect.com/lean/documentation/topic5664.html

How could I go about using this? I don't see what parameters it takes/how to actually use it as an order.

Thanks in advance!

Update Backtest







Hi Philip, sorry we don't support the trailing stop order at this time. You can find all the available order types in documentation

https://www.quantconnect.com/docs/algorithm-reference/trading-and-orders
1

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.


If you want, you can emulate your own trailing stop loss by something akin to the below:

  1. Create a RollingWindow<decimal> (with some suitable maximum size) to store the profit of the symbol you're trading at each time step. This can be found inside Securities[key].Holdings.UnrealizedProfit
  2. At each time step, find the max of this window and compare it to the current profit
  3. If this profit is low enough to trigger a stop, simply exit your position
1

I actually implemented something similar to that, but I used a decimal list and clearing it upon exit instead of using a RollingWindow. Haven't gotten it working yet but I'm going to keep working at it. Perhaps I'll try the RollingWindow - the advantages to that would be that it runs faster/uses less memory, right? 

0

Hi Philip Grossman,
As Jing pointed out, we don't support this kind of orders yet. Therefore you will be emulating the behavior or a trailing stop order. I would suggest you look at how we have implemented the Trailing Stop Risk Management Model.
Please try that approach and share your algorithm for further directions if you have other questions.

0

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.


Update Backtest





0

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...

This discussion is closed