Hi All,
I have attached a backtest that shows an example situation where my order is not filling due to insufficient buying power. I have a suspicion it is due to my one cancels the other order function (Taken from: https://www.quantconnect.com/forum/discussion/1700/support-for-one-cancels-the-other-order-oco/p1, thank you JayJayD)
The console shows an error, and the logs show the buying power is reduced, even though there are no open holdings/cash.
Could someone please help me submit the order of NVEE in the attached backtest with OCO orders. The goal is to create an algo that OCO orders can be created, but the entire portfolio (and pending orders) can also be liquidated/cancelled separately
Link Liang
Hi Lucas,
On line 58, the limitorder is on the same direction as the original order. Since 98% of buying power long is already used, the "insufficient buying power" error is thrown and all the following strategies break. I believe both "take profit" and "stop loss" order should be in the opposite direction to the original order.
Besides, for short, the "take profit" should be StopMarketOrder and "stop loss" should be LimitOrder. You could find more information about order type here.
In your algorithm, the range between take profit and stop loss is a little wide and neither of those two are triggered. To demonstrate the OCO strategy, I've modified those numbers in my backtest. Hope it helps!
Lucas
Hi Link Liang, thanks for taking the time to reply back to me and for picking up in the line 58 error.
In the example the SL & TP are deliberately unrealistically high. What I am trying like to do is simulate a scenario where they arent reached but a better opportunity presents. In the backtest on line 63 I deliberately use Liquidate() in attempt to get back to 100% margin.
With your attached backtest, if I increase the SL/TP size (so that either arent triggered), I run into the same issue of insufficient buying power. Could you please share any insight on this?
Lucas
Hi Link Liang, I realised this may not have anything to do with the OCO function. Because of this, please disregard my previous comment as I have created a new post.
https://www.quantconnect.com/forum/discussion/5792/does-ib-brokerage-model-include-immediate-settlement/p1Lucas
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!