I need help to solve this problem,
I have a strategy that I am running in 2 different times, 1 minute and 2 minutes at the same time, I tell you that if it is 1:00 pm and you have an open operation, you should close it and cancel all pending orders.
The problem is the following:
For example, we have an order with 10 long, at 1:00 pm, when the program runs, in a time frame of 1 minute I see the 10 positions and it takes me out of the position, and at the same time the time frame of 2 minutes comes and it takes me out too. of the long, it remained in a position of 10 In short, and the Cycle is repeated, falling in an endless loop.
private void StopStrategy(){
// Verificar si ya estamos planos o ya estamos cerrando una posición
if (isFlat || isClosingPosition)
{
return;
}
isClosingPosition = true;
// Detener procesamiento y cancelar órdenes
haltProcessing = true;
CancelAll();
if (PositionAccount.MarketPosition == MarketPosition.Long && isClosingPosition){
SubmitOrderUnmanaged(1, OrderAction.SellShort, OrderType.Market,PositionAccount.Quantity, 0,0,"","Cierre por Horario Bull");
isClosingPosition = false;
}
else if (PositionAccount.MarketPosition == MarketPosition.Short && isClosingPosition){
SubmitOrderUnmanaged(1, OrderAction.BuyToCover, OrderType.Market,PositionAccount.Quantity, 0, 0,"","Cierre por Horario Bear");
isClosingPosition = false;
}
}

Comment