Back

Invalid order status in live trading

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.
Update Backtest








Hey Jiaqi, the orders are submitted on the same time step as you call the SetHoldings function. The issue is that if you place a market order at 4:00pm then the exchange is closed. We'll internally convert this into a market on open order for you, which will receive a fill price at 9:30:00am (the opening price), but since you're using second or minute resolution, the fist data point is from 9:30:00-9:30:01 or 9:30-9:31, which is the time you're seeing.

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.


Got it and thank you for the clarification.

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