I'm working with a strategy that enters two trades with the same stop loss and two different targets.
What I'm trying to do is that if the firstTPShort is filled, then set the Short2 trade is set to break even.
Here's the code I have:
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (condition == true)
{
SetStopLoss("Short1", CalculationMode.Price, stopLossShort, false);
SetProfitTarget("Short1", CalculationMode.Price, firstTPShort);
SetStopLoss("Short2", CalculationMode.Price, stopLossShort, false);
SetProfitTarget("Short2", CalculationMode.Price, secondTPShort);
shortOrder1 = EnterShortStopMarket(0, true, 1, adjustedSessionLow, "Short1");
shortOrder2 = EnterShortStopMarket(0, true, 1, adjustedSessionLow, "Short2");
}
}
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
{
if (shortOrder2 != null)
{
Print("Estado de Short2: " + shortOrder2.OrderState);
if (shortOrder2.OrderState == OrderState.Filled || shortOrder2.OrderState == OrderState.Accepted)
{
double breakEvenPriceShort = Position.AveragePrice; // Usar el precio promedio de la posición actual como el nuevo StopLoss
Print("Moviendo StopLoss de Short2 a BreakEven en: " + breakEvenPriceShort);
//ChangeOrder(shortOrder2, shortOrder2.Quantity, breakEvenPriceShort, shortOrder2.StopPrice);
ExitShortStopMarket(1,19513.75,"","");
}
else
{
Print("Short2 no está en estado Filled o Accepted, no se mueve el StopLoss.");
}
}
else
{
Print("shortOrder2 es null, no se puede ajustar el StopLoss.");
}
}
I tried many different things, can anyone help me?

Comment