Hi Community,
I'm revising the Open Range Breakout strategy to long SPY if current price of SPY crosses above the last 30 min bar in the pre-market (9-9:30am). I try to create a rolling window that stores the current 30min bar and the previous 30 min bar. I want to exit the trade if current price of SPY crosses below the previous 30min bar low. But somehow the algorithm only knows how to enter the trade but the exit function does not work properly. Could someone help me out and point out where I did wrong?
Many thanks!
Jay
Fred Painchaud
Hi Jay,
Look at this code. I think it works as you want. If you don't understand changes, don't hesitate to ask questions.
Fred
AK M
Hey Jay,
In your code you have:
Which means once you have opened a position, your code will never get past the return. I think to do what you're trying to do, you'll have to move this self.Portfolio.Invested check to the other two lines. I've implemented what I think you're going for (attached).
Debugging on browser IDE can be tough but in the future printing statements like self.Debug("I am here") might be beneficial to you.
Hope that helps!
Fred Painchaud
😊
Yeah…
Here is the version where I do not skim over the first OnData condition…
If you feed bars in OnData to your window, you are feeding minute bars but it seems like you want 30min bars there…
Fred
Jay Zhao
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!