Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

    BertrandNinjaTrader Customer Service

    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().
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by arvidvanstaey, Today, 02:19 PM
        4 responses
        11 views
        0 likes
        Last Post arvidvanstaey  
        Started by samish18, 04-17-2024, 08:57 AM
        16 responses
        60 views
        0 likes
        Last Post samish18  
        Started by jordanq2, Today, 03:10 PM
        2 responses
        9 views
        0 likes
        Last Post jordanq2  
        Started by traderqz, Today, 12:06 AM
        10 responses
        18 views
        0 likes
        Last Post traderqz  
        Started by algospoke, 04-17-2024, 06:40 PM
        5 responses
        47 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X