Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss not moving

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

    #16
    Good information, Thank you!

    Comment


      #17
      trail stop not moving

      Good day, I have made a simple code for a long strategy with a trailing stop loss under low of closed bar. But StopLoss does not move and every trade ends up at close of the day. Can u offer me advice? Thanks Zdenek

      {
      #region Variables
      // Wizard generated variables
      // 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;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      { if (Position.MarketPosition == MarketPosition.Flat)
      {
      SetStopLoss(CalculationMode.Ticks, Low[0]-TickSize);
      }
      else if (Position.MarketPosition == MarketPosition.Long)

      {
      SetTrailStop("", CalculationMode.Ticks, Low[0], false);
      }
      // Condition set 1
      if (Close[0] > Open[0])
      {
      EnterLongStop(DefaultQuantity, High[0] + 1 * TickSize, "");
      }
      }

      #region Properties
      [Description("")]
      [GridCategory("Parameters")]
      public bool ControlOne
      {
      get { return controlOne; }
      set { controlOne = value; }
      }
      #endregion

      Comment


        #18
        Hello squashfan,

        What is the interval that you are running this script in?

        Is this script being run with Calculate on bar close set to True or False?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Hi Chelsea, it is run on 5 min bars, CalculateOnBarClose = true; Squashfan

          Comment


            #20
            Hello squashfan,

            I am seeing a issue with the setting of the trail:
            SetTrailStop("", CalculationMode.Ticks, Low[0], false);

            You are setting the trail using ticks but you are supplying a price. The trail is likely trailing the number of ticks away that the low of the price bar is. Meaning if the low of the bar is 1500, the trail is trailing 1500 ticks away from the current price.

            Try setting this to a number of ticks. If you want the trail to trail 5 ticks from the current price use:
            SetTrailStop("", CalculationMode.Ticks, 5, false);
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            58 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            39 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            19 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            21 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            51 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X