Hi all,
I was recently attempting to set up a position whereupon the stock increasing 10%, the stop loss would trigger and it would buy back the shares that it had sold short, however in backtesting, I can't seem to verify it ever happening despite numerous tests. I've
included the code below.
order = self.CalculateOrderQuantity(self.symbol, 1)
self.Buy(self.symbol, order)
self.StopMarketOrder(self.symbol, order, (1.1 * data[self.symbol].Close))
Thanks!
Rahul Chowdhury
Hey Nathan,
It sounds like you want a stop market order which purchases back shares after a short, however your algorithm enters 2 long positions. Maybe you meant to Sell, instead of Buy
self.Sell(self.symbol, order)
It may be possible that there is not enough margin for the stop market order to execute. However, I could not reproduce your issue; it is difficult to debug the issue from the code provided. Please attach a complete code snippet or a back test which produces the issue. It will help us better understand the issue.
Best
Rahul
Nathan Wisner
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!