I used strategy builder to create the strategy below. The issue is it executes the exit order twice. Which causes me to enter a short position and the strategy to be terminated.
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if ((Position.MarketPosition == MarketPosition.Flat)
// Condition group 1
&& ((BarsSinceExitExecution(0, "", 0) == -1)
|| (BarsSinceExitExecution(0, "", 0) > 1))
&& (Close[0] >= High[1])
&& (Times[0][0].TimeOfDay >= TradeWindowStart.TimeOfDay)
&& (Times[0][0].TimeOfDay < TradeWindowEnd.TimeOfDay))
{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
// Set 2
if (
// Condition group 1
((Low[0] <= Low[1])
&& (Position.MarketPosition == MarketPosition.Long))
// Condition group 2
|| ((Position.GetUnrealizedProfitLoss(PerformanceUnit .Ticks, Close[0]) >= ProfitTarget)
&& (Position.MarketPosition == MarketPosition.Long)))
{
ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
}
}

Comment