I whipped up a strategy which enters a market position on the 5th bar of each session, then in the OnOrderUpdate, when the order is filled, it places a stop and a target. (I know about SetProfitTarget, but I want to use partials and I keep getting glitches so I'm doing it manually. I also don't want to use 3-4 separate entries with separate targets & stops because the commission and slippage for fragmented orders will eat me alive.)
Anyway, when I take an order with BarsInProgress==0, then everything works well. I enter the position and either get stopped out or I hit my target, life is good.
BUT, when I take an order with BarsInProgress==1, then my stop and limit orders get rejected. The message in the OutputWindow is that I don't have a position, yet before sending the order, I explicitly check (Position.MarketPosition != MarketPosition.Flat).
I can't figure out what's going on. It looks like this is a bug and the position is not being updated correctly for multi-instrument strategies. (I was noticing similar glitches with placing advanced orders.)
To show you what I'm doing, I'm attaching 'TimeframeDemoStrategy'.
I run it with AAPL using 1min data from Apr 17 - 24th, BarsRequired = 0. The strategy will load BIDU for the same period and take four trades, all of which will get stopped out at the end of day.
Then change the Add() line to be "AAPL" and the "BarsInProgress == 0" and run the strategy against BIDU. We've just switched the instruments from position 0 to 1 and vice versa, so the results should be identical. Instead, when BIDU is in position 0, the strategy hits its stop orders and profit targets!

Comment