Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problems with SetTrailStop

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

    Problems with SetTrailStop

    Hi!

    I am having problems with the SetTrailStop orders.

    The code for testing the issue is just:

    public class PruebaTrail : Strategy
    {
    #region Variables
    // Wizard generated variables
    private double trail = 300; // Default setting for Trail
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    SetTrailStop(trail);
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    EnterLong();

    }

    I attach a image in which there is a trade and Trail Stop is working as a StopLoss of 300 € ( Image refer to Ibex35, where every point is 10€) I think It should exit the position before and with some profit instead of what the program is actually doing... Am I wrong?

    Thanks!
    Attached Files

    #2
    ppr4826, for this task please use the CalculationMode option and enter by how many tick to trail the market then - with your setting you just defined a regular stop loss level in currency.

    Comment


      #3
      Thanks for your answer.

      So SetTrailStop(300) will do the same as SetStopLoss(300), right?

      Using CalculationMode.Ticks do what I want, but there is still a problem:

      Setting the TrailStop to 30 ticks and entering long, if the bar where I open the position have an High higher or equal to 30 ticks over the open price, then, the TrailStop is triggered and the position is closed at the same price it was open. There is any way of avoid this? (let me know if you need a picture)

      Comment


        #4
        Correct - you could activate the trail only on the next bar (BarsSinceEntry) in the OnBarUpdate().

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        601 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        347 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        559 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        558 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X