Back

Options Market Order Not Functioning

Please look at this code and tell me what I'm missing. I've isolated the error down to the "MarketOrder" command. This always gives me an error code of "-10" and the order does not execute. I tried varying the order quantity down to 1 contract to eliminate margin issues. And based on 1 discussion I saw that you have to wait one minute on option calls after binding the contract to the symbol. This code does that.

 

Still, no dice.

 

Appreciate any input.

 

 

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.


If I test the orderId variable I get the response: -10 Request Count: 1 Response.Count: 1

 

0

Hi Serge,

In the PrepCall method, you are submitting a MarketOrder right after adding the option contract. Since data is not available for the option contract yet, the -10 UnableToFindOrder error is triggered. You need to wait for one cycle before submitting the order. Please see the attached backtest. When I was debugging your algorithm, more errors showed up. These errors are related to your algorithm, so I will leave them for you as you refactor the algo. Hope this helps! Please let me know if you have further questions!

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.


Hi Alethea,

Well having to wait 1 cycle for the options contract to generate a price point would have required me to drop down to a tick or 1 second cycle, or have to wait 1 whole minute before placing my option order. A lot of price movement can happen in 1 minute...

So I took a different approach, which is shown here. This successfully buys and sells both the stock and the underlying options. But now I have a new issue, which I've spent the last 4 hours chasing down, to no avail

11573_1567007153.jpg

 

Look at the last two entries. These are essentially reversing my last two options orders 2 minutes and 4 minutes after I first successfully execute them. What gives? 

I thought it might be a liquidation event due to margin calls, but I ruled that out by testing with only 50 percent of my portfolio,. I get the same results.

I then suspected something was going on with the EmitInsights call, so i also suppressed that. Yet the problem persists.

I sure hope you can cast some light on this. Meanwhile, maybe some other poor soul can use the function I wrote at the bottom "parseKeysToTypes". This breaks the slice object into its component arrays by type : securities,, options, forex, etc. I needed to do that because you cannot run a History call on a slice object containing both Securities and Options. There may be a more elegant solution, but this one works for me.

Thanks

Serge

 

0


Had not heard back, but I finally took a step away from my code and then my error became obvious.  I was using a Trailing Stop on my long stock position, but this was also being applied to my options, which of course are way more volatile than the underlying stock.  

Setting the risk management to null fixed the problem

#self.SetRiskManagement(TrailingStopRiskManagementModel(0.0172))
self.AddRiskManagement( NullRiskManagementModel() )

 

0

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