I have what I would think should be a relatively uncomplicated strategy. I buy a stock, then when I sell that stock, I buy another stock, then when I sell that second stock, I buy back the first stock. Of course, the circumstances that trigger the sells vary but for the purposes of my problem, I think this is all you need to know.
Here's the code (in essence):
//(at the beginning of the session)
ioEntryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Market, intNumShares, 0, 0, "", "Stock1");
//(when the exit trigger is met)
ioExitOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Market, intNumShares, 0, 0, "", "Stock1");
//(when the exit order is filled and ioExitOrder is null)
ioEntryOrder = SubmitOrder(1, OrderAction.Buy, OrderType.Market, intNumShares, 0, 0, "", "Stock2");
//(when the exit trigger is met)
ioExitOrder = SubmitOrder(1, OrderAction.Sell, OrderType.Market, intNumShares, 0, 0, "", "Stock2");
//(when the exit order is filled and ioExitOrder is null)
ioEntryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Market, intNumShares, 0, 0, "", "Stock1");
Rinse, Repeat, etc. Pretty straightforward, right?
But here's the kicker - the ioEntryOrder for the second stock *frequently* results in a *BuyToCover* order. This makes absolutely no sense to me - the code *explicitly* calls for an OrderAction of "Buy" whereas "BuyToCover" is nowhere in sight in my code.
I also don't see how this a position vs. strategy synchronization issue. After all, I don't hold anything (long OR short) in Stock 2 at the time the second ioEntryOrder takes place, so I'm not sure why NinjaTrader assumes what my position is before placing the order. Wasn't the major benefit behind unmanaged orders supposed to allow us to completely ignore the position/strategy synchronization differences in the first place?
It's always frustrating to turn on live a strategy, which has had *no* problems in backtesting, only to come home and find out that it decided to do something completely unexpected and break as a result.
Any help here would be appreciated. Thanks!
Comment