Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

can anyone tell me what is wrong with this logic regarding a trailing stop?

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

    can anyone tell me what is wrong with this logic regarding a trailing stop?

    I'm trying to add a trailing stop to my script manually and i cant figure out what the issue is. Every time i compile the script, all seems well, but when the orders are filled during trading hours, there is no sign of a trailing stop order opening. As a matter of fact, when I back test my script, it shows losses of >$2,000. This is extremely high relative to where my stop losses should be set initially.

    Maybe I'm getting it confused. Should I add language to set an initial stop loss at a certain amount of ticks, then have a trailing stop take over?

    I'm new to the Algo game, so any help would be much appreciated.

    // Update trailing stop logic
    if (Position.MarketPosition == MarketPosition.Long)
    {
    double stopPrice = Low[0] - 6 * TickSize; // Calculate 6-Tick trailing stop
    if (High[0] > High[1]) // Check if current high is greater than previous high
    {
    stopPrice = Math.Max(stopPrice, High[0] - 6 * TickSize); // Adjust stopPrice based on current high
    }
    SetTrailStop(CalculationMode.Price, stopPrice);
    }
    else if (Position.MarketPosition == MarketPosition.Short)
    {
    double stopPrice = High[0] + 6 * TickSize; // Calculate 6-Tick trailing stop
    if (Low[0] < Low[1]) // Check if current low is lower than previous low
    {
    stopPrice = Math.Min(stopPrice, Low[0] + 6 * TickSize); // Adjust stopPrice based on current low
    }
    SetTrailStop(CalculationMode.Price, stopPrice);
    }​
    Last edited by jbays87; 05-06-2024, 09:58 PM.

    #2
    Hello jbays87,

    To know if the stop is being called you would need to add a print into this section of code to get a better idea of what is happening. You could add prints into the code below each of the SetTrailStop lines to make sure those orders get called. If you have another stop working already that may be why you are not seeing the trailing stop, a trailing stop can only be used by itself. It will be ignored if you have a stop working already.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    53 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X