Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Difficulty resetting Trailing stop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Difficulty resetting Trailing stop

    Hello,

    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);
    }
    }

    #2
    Hello Jorge.andres.o,

    When you say reset the trail stop what specifically do you mean? Are you trying to change the price you are using or what specifically is the problem that you are trying to solve?

    I see that you have some exit orders and provided what appears to be part of one of our samples. Are these both in the same script or was the second syntax just an example of a trailing stop in general?

    I look forward to being of further assistance.

    Comment


      #3
      Jesse,

      thanks for the reply. Everything is in the same strategy. I understood that I have to reset stop to go back to initial values.

      however, I have many stops. I cannot figure out how to reset them

      Comment


        #4
        Hello Jorge.andres.o,

        I understood that I have to reset stop to go back to initial values.
        Are you referring to a break even?

        If you mean to just reset the stop after the order fills, you don't need to do that. You just need to make sure to call SetTrailStop before entering the position to make sure it has a correct value for that entry.

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        90 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        152 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        80 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        53 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        63 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X