Hi,
Is there an example how to implement more than one strategy but each one saved in a different .py file? The file would define what actions to take in OnData. Ideally would define what datasets to add in Initialise. Not keen to use the Algorithm Framework approach.
Thanks.
Mia Alissi
Here is an example setup based on your requirements, where you have multiple strategies in separate .py files, each with its own initialization (datasets, indicators, etc.) and trading logic. The main algorithm imports and orchestrates them.
main_algorithm.py
strategy_one.py
strategy_two.py
How to use this template:
You can scale this pattern to as many strategies or asset classes as you want!
Sources: Multiple Symbol Consolidation Algorithm, Dual Thrust Trading Algorithm, Hybrid Algorithms - QuantConnect.com, Basic Template Option Strategy Algorithm, Multi-Asset Modeling - 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.
Dat En
Thanks so much Mia Alissi . You're a superstar!!
Mia Alissi
Thank you so much for your kind words! I'm thrilled I could help. If you ever have more questions or need assistance with QuantConnect, please don't hesitate to ask. I'm here to support you, and I truly appreciate the shoutout!
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.
Dat En
Sorry Mia Alissi - is there a constraint when creating new files? They seem to disappear after I close and reopen the project. Same thing occurs if I clone an existing project and try to create a new file. Looked the the doc below and I don't think I'm doing anything wrong.
Mia Alissi
It sounds frustrating, but you’re not alone—this issue can happen due to a few common reasons:
.py
,.cs
,.ipynb
,.md
) will persist in QuantConnect projects. Unsupported file types may disappear when you refresh or sync the project. Here’s the list of supported file types.lean cloud push
andlean cloud pull
to sync changes between your machine and the cloud. Unpushed files may not persist.If you’ve double-checked the above and still see issues, let us know your workflow and we’ll help dig deeper. Don’t hesitate to reach out if you need more assistance!
Sources: Cloud Synchronization - QuantConnect.com, Libraries - 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.
Dat En
Thanks Mia Alissi just realised I need to specify the file extension. Sorry for the extra questions. Now the backtest seems to have gone into a Runtime error. Any tips from here?
Mia Alissi
Great catch on the file extension issue! For the Runtime Error, here are some actionable steps to help you debug:
self.Debug()
orself.Log()
statements right before the lines where you suspect errors; printing out variable values can reveal unexpected results.You're making fantastic progress—debugging is a skill, and you’re sharpening it!
Sources: Debugging - QuantConnect.com, Debugging Tools - 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.
Dat En
Hey Mia Alissi you're so quick! I shared the stack trace in the previous post as an image. It doesn't appear to be related to the code (I copied exactly your code above), but related to Lean. Here is the stack trace text:
[ERROR] FATAL UNHANDLED EXCEPTION:PythonInitializer.AddAlgorithmLocationPath(): Unable to find algorithm location path: .,Engine.Main(): Sorry we could not process this algorithm request.,Unhandled exception. System.ArgumentException: Engine.Main(): Sorry we could not process this algorithm request., at QuantConnect.Lean.Launcher.Program.Main(String[] args) in /LeanCloud/CI.Builder/bin/Release/src/QuantConnect/LeanEnterprise/Launcher/Program.cs:line 75, runLauncher.sh: line 18: 7 Aborted (core dumped) dotnet QuantConnect.Lean.Launcher.dll --data-folder /Data --config /QuantConnect/backtesting/airlock/config.json --results-destination-folder /QuantConnect/backtesting/airlock/
Mia Alissi
This error usually means the algorithm entry point file is missing, misnamed, or not set up correctly. Here are some things to check:
If you need help checking these, or want to share your current file list, I’m happy to walk through it with you!
Sources: Debugging - 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.
Dat En
Thanks for you patience Mia Alissi Just realised the main entry point should be named exactly main.py! Works now thanks to you !!
Mia Alissi
Congratulations! Your dedication and perseverance have truly paid off. I'm so glad to hear that renaming the main entry point to 'main.py' solved your issue. Thanks for sticking with it, and for your kind words too! Please don't hesitate to reach out again if you ever need more help or run into any other questions—I'm always happy to lend a hand!
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.
Dat En
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!