Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Loss not working

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

    Stop Loss not working

    Somehow I can´t get my StopLoss Orders to work correctly in the strategy analyzer. The StopLoss order executes on the same bar as the entry order. Could somebody please tell me what I´m overlooking?

    I created with the Wizard the following code:
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class AAAStopLossSSMAcross : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int fast = 5; // Default setting for Fast
    private int slow = 10; // Default setting for Slow
    private double stopLoss = 0; // Default setting for StopLoss
    // 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()
    {
    Add(SMMA(Close, Fast));
    Add(SMMA(Slow));
    SetTrailStop("BuyIt", CalculationMode.Percent, StopLoss, true);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(SMMA(Close, Fast), SMMA(Slow), 1))
    {
    EnterLong(DefaultQuantity, "BuyIt");
    }

    }

    #region Properties
    [Description("")]
    [Category("Parameters")]
    public int Fast
    {
    get { return fast; }
    set { fast = Math.Max(1, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public int Slow
    {
    get { return slow; }
    set { slow = Math.Max(1, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public double StopLoss
    {
    get { return stopLoss; }
    set { stopLoss = Math.Max(-10, value); }
    }
    #endregion
    }
    }

    #2
    Hi moon_121,

    One of our NinjaScript trainees will respond to you at a later point in time. Thank you for your patience.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hello Moon_121,

      Thank you for your post.

      "Set" orders are submitted upon entry execution so it's possible to be filled intrabar.


      When using StopLoss statements in percent, use the decimal value representing the percent:
      10% should be .1
      1% should be .01

      There is also one line of code that suggests you may be using negative values for your stop loss.
      set { stopLoss = Math.Max(-10, value); }

      All stop losses should use positive values. If you wanted a stop loss 20% below your entry price, you should still use a positive value .2
      Ryan M.NinjaTrader Customer Service

      Comment


        #4
        OK

        Thanks guys - everything is working now. The problem was the negative value for the stop loss.
        The great support from NT ist one of the reasons to buy this software!

        Comment


          #5
          Can anyone tell me how to place stop-loss order? I found this information is does it correct at all? http://investinganswers.com/term/stop-loss-order-1102 Thanks beforehand!

          Comment


            #6
            stoploss, welcome to our forums here - please check into this thread for how to protect a 'naked' position.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Nice, thanks for the help!

              Comment


                #8
                My error as same as moon_121

                Porn Clips
                Adult Online Dating

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by f.saeidi, Today, 11:02 AM
                1 response
                1 view
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by geotrades1, Today, 10:02 AM
                4 responses
                12 views
                0 likes
                Last Post geotrades1  
                Started by rajendrasubedi2023, Today, 09:50 AM
                3 responses
                16 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by lorem, Today, 09:18 AM
                2 responses
                11 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by geddyisodin, Today, 05:20 AM
                4 responses
                30 views
                0 likes
                Last Post geddyisodin  
                Working...
                X