Can I get confirmation from someone on when "Performance.AllTrades" is set...? If I've just had a position flattened, is that trade already written into by the time I go into OnPositionUpdate?
Here's the problem. I need to know the price I exited at... and I've been using Performance.AllTrades to figure out that price (scanning through looking for matching instrument name.) I'm doing this in OnPositionUpdate instead of OnExecution/OnOrderUpdate because of reports those might be wrong on IB.
This has worked really well in the past, but just threw me a weird exception suggesting Performance.AllTrades was empty at the time when it executed. I'm printing line numbers, so I know it happened on this line:
Trade latestTrade = null;
for (int index = Performance.AllTrades.Count-1; index >= 0; index++)
{
latestTrade = Performance.AllTrades[index];
if (latestTrade.Entry.Instrument.FullName == Instrument.FullName)
break;
}
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.CollectionBase.System.Collectio ns.IList.get_Item(Int32 index)
at NinjaTrader.Strategy.TradeCollection.get_Item(Int3 2 index)
at NinjaTrader.Strategy.ProtectDownMulti.OnPositionUp date(IPosition position) in c:\Documents and Settings\Chon\My Documents\NinjaTrader 6.5\bin\Custom\Strategy\ProtectDownMulti.cs:line 942
System.Collections.IList.get_Item
Line: 0
Column: 0

Comment