Hi there,
I just want implementing trade counting system that counts the open trades. For securing my account against big loses.
And if the maximum open trades (for ex max 5 open trades) are reached that there are no new orders being made.
And if a trade is closed that the counting system reduces the open trades with 1.
Thanks in advance.
Nico Xenox
Hey vronghel
You can check the invested values in the Portfolio with this code:
That way we can check the lenght in “invested”:
This way the algo stops investing after 5 orders. If you sell an asset it will automatically go down because it always checks the number before investing into another asset.
Hope it helps ;)
Vronghel
Hi Nico,
Thanks for the answer.
But is it possible to translate it to C# cause I'm not familiar with python.
Thanks in advance.
Nico Xenox
Hey vronghel
I have not really an idea of c# but thats what I came up with, there is still an error in the code maybe you can solve it.
Vronghel
Hi Nico,
Thanks for trying to convert the code to c#.
But I cant find the correct answer either without the errors.
Derek Melchin
Hi Vronghel,
See the attached backtest for a working C# example. We can't always use the logic of counting the number of invested assets in the portfolio like the earlier examples because it doesn't work in all cases. For example, if we use daily data, the orders aren't filled until the following bar.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Vronghel
Hi Derek,
Thanks for your answer.
Vronghel
Hi Derek,
I Implemented the counting method in my code but the problem is that there is an invalid order the counter still raised with 1 even though there is no trade been placed.
Is it possible to count the assets in my portfolio? So that there can be a maximum of altcoins in my portfolio?
Thanks in advance.
David
Louis Szeto
Hi Vronghel
To handle that, move the counting process into OnOrderEvent handler such that we can only count if an order got fully filled:
Best
Louis
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.
Vronghel
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!