I have a script that only opens long trades in a unmanaged approach.
I save all long orders in a collection. I get the total size opened like this:
int size = 0;
foreach(Order o in orders)
{
if (o.OrderState==OrderState.Filled)
{
size+=o.Quantity;
}
}
And I open a short hoping to exit all long trades:
string oco;
if (State == State.Historical)
oco = DateTime.Now.ToString() + CurrentBar;
else
oco = GetAtmStrategyUniqueId();
SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Market, size,0,0,oco, "ExitAllLongs");
But the long trades doesnt close till they touch theirs take profit or stop loss, and now I have a market short opened.
What im doing wrong?
Cold you give me some sample code showing how to exit opened trades in a unmanaged approach?
Thank you!
Comment