I have two strategies, in the same algo. Both are entering GLD on certain levels. They enter with SetHoldings and exit with the Liquidate methods. How can I make sure, that they don't cancel each other out? If one strategy has an active position and the other position has an exit signal, it must not liquidate the first position.
Mia Alissi
To ensure that your two strategies do not cancel each other out when using
SetHoldings
andLiquidate
, you can implement a tagging system to manage and track which strategy owns which positions. Here's how you can do it:Assign Unique Tags: Use the
tag
parameter in bothSetHoldings
andLiquidate
methods to label orders with a unique identifier for each strategy.Track Strategy Positions: Maintain a record of which strategy owns which positions. This can be done using a dictionary or a custom data structure.
Conditional Liquidation: Before executing a
Liquidate
command, check if the position belongs to the strategy that is issuing the exit signal. Only allow liquidation if the position is owned by the strategy.Here's an example implementation:
Key Points:
tag
parameter to differentiate between strategies.This approach will help you manage multiple strategies within the same algorithm without them interfering with each other.
Sources: Dual Thrust Trading Algorithm, Liquidating Positions - QuantConnect.com, Portfolio Target Tags Regression Algorithm, Covered And Protective Put Strategies Algorithm, Covered And Protective Call Strategies Algorithm
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.
David Maucher
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!