Dear All,
I have a question regarding the invalid order status in live trading. I am test live trading my IB paper trading account with a simple SMA cross algo using hourly bars to see whether the order could be placed correctly as I can directly observe the SMA cross signals using bar charts from my broker. The logic is very simple as following:
var holdings = Portfolio[Symbol].Quantity;
var holdings2 = Portfolio[Symbol2].Quantity;
if (holdings <= 0)
{
if (fast > slow )
{
Log("SELL >> " + Securities[Symbol2].Price);
Liquidate(Symbol2);
Log("BUY >> " + Securities[Symbol].Price);
SetHoldings(Symbol, 1);
}
}
if (holdings > 0 && fast < slow)
{
Log("SELL >> " + Securities[Symbol].Price);
Liquidate(Symbol);
Log("BUY >> " + Securities[Symbol2].Price);
SetHoldings(Symbol2, 1);
}
It worked very well in backtest in terms of execution but the 3rd order in my live test the buy order for Symbols was not executed. The status in my live project is shown as below
32016-01-13 12:01:00VXX 41,353 MarketLong Invalid
22016-01-13 12:01:00XIV$21.331492332192 -45,841 MarketShort Filled
12016-01-12 10:01:00XIV$21.849520080277 45,841MarketLong Filled
Any idea what happened at the API? I am using long only market orders so there should be any issue about unable to borrow stocks to short. Anyone encountered the same problem? My current thinking is that maybe at the moment of the third order I have slightly insufficient capital to place the market order due to price fluctuation. So if I change SetHoldings to 0.99 it could solve the problem or if I am using my real margin account I can buy on margin to avoid the problem. But if the price fluctuation is the problem how come the first order is filled w/o any problem? I am quite lost here before I can live test more complicated algos.
Any suggestion is appreciated. Thanks.
Nicholas Stein
Jiaqi chen
Jared Broad
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.
Jiaqi chen
Michael Handschuh
Nicholas Stein
Jiaqi chen
Jiaqi chen
Jiaqi chen
Jared Broad
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.
Jiaqi chen
Nik milev
Jiaqi chen
Jared Broad
Transactions.MarketOrderFillTimeout = TimeSpan.FromMinutes(30);
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.
Nicholas Stein
Jiaqi chen
Nik milev
Jiaqi chen
Hi guys, Thanks for all the suggestions especially on using Transactions.MarketOrderFillTimeout = TimeSpan.FromMinutes(30); and Nicholas' sample code of handling different order types. With the new master lean engine and a setup of Transactions.MarketOrderFillTimeout = TimeSpan.FromMinutes(10); my naive paper trading test using 5 mins consolidated bars were successful during the weekdays. But it mysteriously continued to place an order on Saturday and I have received the following message: Runtime Error: Algorithm took longer than 10 minutes on a single time loop. Stack Trace: at QuantConnect.Isolator.ExecuteWithTimeLimit (TimeSpan timeSpan, System.Func`1 withinCustomLimits, System.Action codeBlock, Int64 memoryCap) [0x00000] in :0 at QuantConnect.Lean.Engine.Engine.Run (QuantConnect.Packets.AlgorithmNodePacket job, System.String assemblyPath) [0x00000] in :0 User: 9707, Project: 207541, Algorithm: L-6013a84ec2a556565750d0ce54bd0d8d I am doing nothing fancy but using Order(Symbol,total_qnt,OrderType.Market); to test the order placement In fact this is the second weekend I am see the same error. In the backtest the algo was able to identify the non-tradings days with a problem. I think I may be able to handle this problem by checking whether it is a weekday or more safely, the security.Exchange.ExchangeOpen signal. It still feels weird that I would see such errors during the non-trading days. Any idea how it happens and how to solve it? Thanks.
Jared Broad
@jiaqi chen; correct you shouldn't be able to place an order on Saturday. What code is surrounding / triggering the market order? You might be placing a market order in after market / weekend times which is then converted to a "Market On Open" order.
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.
Jiaqi chen
Hi Jared, I am testing nothing fancy but a simple market order of Order(Symbol,total_qnt,OrderType.Market); on every 5 mins consolidated bars with a minute resolution from AddSecurity(SecurityType.Equity, Symbol, Resolution.Minute); Transactions.MarketOrderFillTimeout = TimeSpan.FromMinutes(10);. Based on what I have seen from the backtest logs I think the market order is placed 1 min after the trigger signal thus if the signal is triggered at 4:00pm EST the algo will place a market order at 9:31am the next day if it is trading day. If I am using a Resolution.Second then the market order will be placed at 9:30:01am the next day if it is trading day. Did I get that part right? If I got this market order placement concept wrong then I can definitely add a time constraint to not fire the order if it is within 3 mins of market close. I use to use setHoldings(xx,xx,1) to flip the positions and I switched to the current cumbersome codes suspecting the setHoldings() function was giving me troubles. I have attached the project for your reference and thank you for your suggestions.
Jiaqi chen
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!