I've tried commenting out each separate chunk of code to narrow it down but it seems to be anything that has to do with the move stop to B/E code
Any ideas? Many thanks.
protected override void OnBarUpdate()
{
// Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, StopLoss);
}
// If a long position is open, allow for stop loss modification to breakeven
else if (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price+30 ticks, set stop loss to breakeven
if (Close[0] > Position.AvgPrice + 30 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
}
}
else if (Position.MarketPosition == MarketPosition.Short)
{
// Once the price is less than price+30 ticks, set stop loss to breakeven
if (Close[0] < Position.AvgPrice - 30 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
}
}
// Condition set 1
if (CrossBelow(ParabolicSAR(0.02, 0.2, 0.02), Close, 1))
{
EnterLong(Contracts, "");
}
// Condition set 2
if (CrossAbove(ParabolicSAR(0.02, 0.2, 0.02), Close, 1))
{
EnterShort(Contracts, "");
}
}
Comment