So what I am trying to do is make a check for when the position is flat to cancel any pending orders. I used ChatGPT to come up with this but when I try to compile it it gives me quite a few errors. I will include a screenshot of them. Here is the code:
// Check if the position is flat
if (Position.MarketPosition == MarketPosition.Flat)
{
// Get all open orders
List<IOrder> openOrders = GetOrders();
// Loop through each order and cancel it if it is a stop order
foreach (IOrder order in openOrders)
{
if (order.OrderType == OrderType.Stop)
{
CancelOrder(order.OrderId);
}
}
}
How can I rectify this or accomplish this goal?
Thanks
Comment