I have a strategy with several entries and stops loss. I am trying to set up a trailing stop after the position is winning. I cannot reset the stops loss because I have several and the examples that I found only show one stoploss.
This are the stops:
private void PlaceBracketExits(int orderNumber, Execution execution, MarketPosition marketPosition)
{
if (execution.MarketPosition == MarketPosition.Long)
{
switch (orderNumber)
{
case 1:
stopOrder01 = ExitLongStopMarket(0, true, execution.Order.Filled, execution.Price - Order01SL * TickSize, "LE01 Stop", "LE01");
break;
case 2:
stopOrder01 = ExitLongStopMarket(0, true, Convert.ToInt32(Order01LotSize), execution.Price - Order02SL * TickSize, "LE01 Stop", "LE01");
stopOrder02 = ExitLongStopMarket(0, true, execution.Order.Filled, execution.Price - Order02SL * TickSize, "LE02 Stop", "LE02");
break;
case 3:
stopOrder01 = ExitLongStopMarket(0, true, Convert.ToInt32(Order01LotSize), execution.Price - Order03SL * TickSize, "LE01 Stop", "LE01");
stopOrder02 = ExitLongStopMarket(0, true, Convert.ToInt32(Order02LotSize), execution.Price - Order03SL * TickSize, "LE02 Stop", "LE02");
stopOrder03 = ExitLongStopMarket(0, true, execution.Order.Filled, execution.Price - Order03SL * TickSize, "LE03 Stop", "LE03");
break;
case 4:
stopOrder01 = ExitLongStopMarket(0, true, Convert.ToInt32(Order01LotSize), execution.Price - Order04SL * TickSize, "LE01 Stop", "LE01");
stopOrder02 = ExitLongStopMarket(0, true, Convert.ToInt32(Order02LotSize), execution.Price - Order04SL * TickSize, "LE02 Stop", "LE02");
stopOrder03 = ExitLongStopMarket(0, true, Convert.ToInt32(Order03LotSize), execution.Price - Order04SL * TickSize, "LE03 Stop", "LE03");
stopOrder04 = ExitLongStopMarket(0, true, execution.Order.Filled, execution.Price - Order04SL * TickSize, "LE04 Stop", "LE04");
break;
This is the code to change to trailing stop:
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, 200); // I know this is not the right way to go back to BracketExits but I am not sure what to write here
}
// If a long position is open, allow for stop loss modification to breakeven
if (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price+50 ticks, set stop loss to breakeven
if (Close[0] > Position.AveragePrice + 50 * TickSize)
{
SetTrailStop(CalculationMode.Ticks, TrailingStop);
}
}
if (Position.MarketPosition == MarketPosition.Short)
{
// Once the price is greater than entry price+50 ticks, set stop loss to breakeven
if (Close[0] < Position.AveragePrice - 50 * TickSize)
{
SetTrailStop(CalculationMode.Ticks, TrailingStop);
}
}

Comment