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 TradeForge, 04-19-2024, 02:09 AM
            2 responses
            28 views
            0 likes
            Last Post TradeForge  
            Started by aprilfool, 12-03-2022, 03:01 PM
            3 responses
            327 views
            0 likes
            Last Post NinjaTrader_Adrian  
            Started by giulyko00, Today, 12:03 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by f.saeidi, Today, 12:14 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by AnnBarnes, Today, 12:17 PM
            1 response
            2 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Working...
            X