I just started using QuantConnect recently, and I must say it's one of the best cloud platform I've used. However I'm finding it difficult to understand the `StopMarketOrder` stop order. Let's say I'm holding 500 shares of SPY, and I want to close the position immediately SPY reaches a particular price
self.StopMarketOrder(self.spy.Symbol, -500, 0.90 * self.Securities[self.spy.Symbol].Close)
When the stop price is triggered, does it close the position or it SELL/SHORT it. ?
Fred Painchaud
Hi Obimba,
If you hold 500 SPY, it will sell your 500 SPY. A negative quantity is selling, a positive one is buying. If you sell something you do not hold, you are short selling. It will put you in a negative position (-500 SPY for instance). Then, when you buy back 500 SPY, you'll reach 0 and you will then exit your short position.
In an nutshell…
Fred
Obimba Smart Chukwunenye
Thanks for your reply. But I'm still not getting it.
I'm trying to update my ‘MarketOrder’ ticket to a new stop loss: that's exciting the position
Fred Painchaud
Hi Obimba,
1- Exiting or closing a position means to sell your holdings if you are long (if you have holdings) or to buy your debt if you are short (buy and give back whatever you have borrowed to go short). So I don't understand when you write “how do I exit/close a position with stop loss without selling it”.
2- Moreover, a “stop loss” means to exit/close a position which is loosing (being long or short).
3- Now, “how to Liquidate my holding for a particular equity with limit”. If you liquidate your holding, you exit/close it, and if you are long in your holding, you sell it. I'm mentioning that to be sure we are on the same page as you are asking to liquidate but also without selling.
To liquidate a position if a limit is reached:
a) if you are long, say 1 SPY, you need to put a limit order for your limit price, say 540 - LimitOrder("SPY", -1, 540). That will put a market order to sell 1 SPY if the price of SPY reaches 540$. Note in live trading the fill price can be “anything” (within volatility reason) below or above 540$.
b) if you are short, say -1 SPY, you need to put a limit order for your limit price, say 540 - LimitOrder("SPY", 1, 540). That will put a market order to buy 1 SPY if the price of SPY reaches 540$. Note in live trading the fill price can be “anything” (within volatility reason) below or above 540$.
In both cases, once your limit order is filled, you are not in your position anymore.
4- “I'm trying to update my ‘MarketOrder’ ticket to a new stop loss: that's exciting the position”. You cannot update a marker order ticket because it is a market order and it should be executed/filled within milliseconds. Once executed, it's too late to be updated. 100% of the brokers I know don't even implement the “update” function on market orders.
Hope this helps!
Fred
Obimba Smart Chukwunenye
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!