// Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, stoplossticks);
}
// 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 + # ticks, set stop loss to breakeven
if (Close[4] > Position.AvgPrice + 13 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
}
}
// If a short position is open, allow for stop loss modification to breakeven
else if (Position.MarketPosition == MarketPosition.Short)
{
// Once the price is less than entry price - # ticks, set stop loss to breakeven
if (Close[-4] > Position.AvgPrice - 13 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
}
Comment