Hello, I have a quick a few quick questions relating to stop and limit orders.
1. In the picture above, how is it possible that stop orders and limit order are invalidated? I can understand market order being invalidated for insufficient buy power, but not stop or limit orders after market order went through.
2. When a limit or stop order gets executed (price reaches that price), does that cancel the other one too? For example if price hits stoploss, does that remove the limit order as well or it stays?
Thanks, Vedran
Vedran Mrkonjic Durokovic
Nevermind I figured it out. If anyone reads in the future:
1. Quant Connect seems to treat margin separately for limit orders and stop orders. That means if your code uses Market order, Limit order and stop order, You need to divide "Total trades" by 3 to get actuall number of trades.
2. Limit Orders do not invalidate stop market orders and vice versa. You need to have a system (I recommend using OnOrderEvent) where on 1 order getting filled you cancel the other one.
I would lock the thread but I can't accept my own answer.
Sean
Hey Vedran, Thanks for answering your own question.
Quick question, I am making a market order in in the OnData method and then creating the stops and limit orders in the OnOrderEvent method, if any of the sell orders are filled then I cancel all existing sell orders. I seem to be getting a similar error to you saying that my limit order is invalid because I don't have sufficient power for both my sell orders.
Do you know why this is happening?
Varad Kabade
Hi Sean,
When we have standing limit orders, we recommend calculating the amount remaining :
And use this to place the orders. We recommend referring to the following example algorithm for more information.
Best,
Varad Kabade
Vedran Mrkonjic Durokovic
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!