Can anyone help me figure out why this foreach loop isn’t iterating?
private void OnAccountItemUpdate(object sender, AccountItemEventArgs aie)
{
if (aie.AccountItem != AccountItem.UnrealizedProfitLoss)
{ return; }
Print(aie.Account.ToString());
if (aie.Account.Orders != null)
{
Print("Orders found.");
foreach (Order theOrder in aie.Account.Orders)
{
Print("Account: " + aie.Account.Name.ToString() + " - Order Name = " + theOrder.Name.ToString() + ", ExitLine[1] = " + ExitLine[1].ToString());
if (theOrder.Name.Contains("Exit")
&& theOrder.OrderState == OrderState.Working
|| theOrder.OrderState == OrderState.Accepted)
{
if (ExitLine[1] > theOrder.StopPrice)
{
theOrder.StopPriceChanged = ExitLine[1];
aie.Account.Change(new[] { theOrder } );
Print("Order changed; qty = " + qty.ToString() + ", Stop Price = " + ExitLine[1].ToString());
}
}
}
}
}
The foreach that isn’t executing is the Order one. I see the Prints for the Account and the “Orders found,” but the Print inside the Order loop never shows up.
Sim102
Orders found.
Sim101
Orders found.
Sim102
Orders found.
Sim101
Orders found.
Sim101
Orders found.
Sim102
Orders found.
Sim101
Sim102
Orders found.
Orders found.
Sim101
Orders found.
All of this is happening while I am in an active Position with stop and target orders in place, which were themselves placed by this same Indicator in OnExecutionUpdate.
This code was copied/pasted from another Indicator which works just fine.
Any ideas?
Thanks in advance!