Hello, I am brand new user to QuantConnect! I would like to backtest the following basic idea for a particular stock. Here is the pseduocode starting with an initial cash of $1,000:
Buy Conidition: If $1,000 cash available and price drops 5% within the last 7 days, buy $1,000 of XYZ
Sell Condition: If price rises 10% since last buy order, sell all XYZ holdings
Is this possible to backtest in QuantConnect? The caveat is that this algorithm would not buy more than once in a row without selling. Also, another important distinction is that the buy condition is irrsepective of ticker price. Let me know if that makes sense!
Joe Hammilton
To be more specific about the buy condition, I imagine the algorithm would compare the current price to the price 1 day ago, 2 days ago, 3 days ago, 4 days ago, etc all the way up to 7 days, and if anyone of those comparisions is -5% it would trigger the buy condition. Let me know if that makes sense!
Jack Simonson
Hi Joe,
This is certainly possible! The best way to do this is to use our Rolling Window feature, which is a method for keeping trade of recent data slices for a given security. You can learn more about Rolling Windows here, but I would recommend that you complete our Boot Camp to familiarize yourself with the QC platform fundamentals and then read the documentation regarding Handling Data and using Indicators as well.
Joe Hammilton
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!