Back

Opening multiple positions on a decreasing trend for the same equity and closing only the ones in profit

Let's say AAPL current price is $1,000.
I open a new position on AAPL for $2,000 (2 shares) (we'll call this "aapl_1").
At some point later AAPL goes down to $900.
I open a new position ("aapl_2") for $2,000 (2.22 shares).
Sometime later AAPL goes back up to $1,000.
How do I close position "aapl_2" to take a profit, while keeping position "aapl_1" untouched?
I've looked everywhere and it seems there isn't a way to close specific positions, unless they have been opened with a take profit option. I can also use a market order to sell stock, but that will sell a generic number, regardless of the opening price. I can also liquidate AAPL, but that means also closing "aapl_1", which is not what I am after.
What have I been missing?

Thank you

Update Backtest







0

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.


Hey Mihai,

You can create a queue of OrderTickets, which contain the fill price and quantity of each new position you enter. Once the downtrend has reversed, the latest entry OrderTicket will be in profit first. As each entry order is in profit (i.e. the current market price is better than the fill price on the OrderTicket), you can create a corresponding exit market order with the same quantity which will close that position. You can do this for each order as it becomes profitable.

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed