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 bortz, 11-06-2023, 08:04 AM
            47 responses
            1,605 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            8 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            4 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            13 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X