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 pechtri, 06-22-2023, 02:31 AM
        10 responses
        124 views
        0 likes
        Last Post Leeroy_Jenkins  
        Started by judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        59 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Yesterday, 06:52 PM
        4 responses
        36 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Yesterday, 07:39 PM
        0 responses
        7 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Yesterday, 03:01 PM
        2 responses
        22 views
        0 likes
        Last Post helpwanted  
        Working...
        X