Hello,
Is it possible to code a strategy like this?
Each day, I want an algorithm to use 25% of my account to long or short TQQQ. If the first 5-minute candle of the day is green, the algorithm opens a long position. If the first 5-minute candle of the day is red, the algorithm opens a short position. In other words, if during the first 5 minutes the market moved up, we take a bullish position starting from the second candle’s opening price. Conversely, if the first 5-minute candle was negative, we take a bearish position at the open of the second 5-minute candle. Please do not open a position when the first 5-minute candle is a doji (open price = close price).
I want the algorithm to close the position if a stop loss of 5% of the 14-day Average True Range is hit. If that stop loss is not it during the day, I want the algorithm to close the position a few seconds before the market closes for the day. Thanks!
Mia Alissi
Here’s a complete QuantConnect algorithm implementing your strategy for TQQQ as described:
How it works:
Let me know if you want to tweak anything or need help deploying/running this algo!
Sources: docs writing algorithms securities asset classes us equity handling data, docs writing algorithms trading and orders order management order tickets, docs writing algorithms portfolio key concepts, docs writing algorithms securities asset classes us equity shorting, Bear Call Ladder - QuantConnect.com
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.
Retrospective Green Ocelot
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!