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);
Log("BUY >> " + Securities[Symbol].Price);
SetHoldings(Symbol, 1);

if (holdings > 0 && fast < slow)
Log("SELL >> " + Securities[Symbol].Price);
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.