Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trail Stop update tick by tick while calculate on bar close

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

    Trail Stop update tick by tick while calculate on bar close

    My strategy calculates on bar close and per the settrailstop() help, the trail stop should be calculated tick by tick. This is not happening though, the trail stop only updates when a new bar opens. How can I fix this through the wizard so the stop is calculated tick by tick?

    #2
    abarb26, in realtime it would be amended tick by tick as it's a real working order unless you're using 'simulated'. In backtest it's updated on per bar basis, as this is how the backtest proceeds through the dataset.

    Comment


      #3
      Thanks for the reply. What about when the system is setup to calculate at bar's end, does the trail stop calculates at the end of the bar as well?

      Comment


        #4
        Yes, it would calculate then at the end of the bar as well - the tick by tick just means how the trailing aspect works, i.e. the new trail stop level is found. If you want to update on each tick, you could work in CalculateOnBarClose = false and work your 'on bar close' logic in FirstTickOfBar - http://www.ninjatrader.com/support/f...ad.php?t=19387

        Comment


          #5
          Originally posted by fredb987
          Bertrand - so if I wanted a strategy to close trailing stop orders in Live mode the same way as in backtesting, I would only have to change this to 'false', correct?

          CalculateOnBarClose = false

          I'm trying to avoid having my trailing stop triggered before the close of a Renko bar.
          To get strategy updates not intrabar, you would need to it to 'true', otherwise your OnBarUpdate() is called on each tick on realtime data, which is not what you seek.

          Comment


            #6
            Originally posted by NinjaTrader_Bertrand View Post
            To get strategy updates not intrabar, you would need to it to 'true', otherwise your OnBarUpdate() is called on each tick on realtime data, which is not what you seek.
            OK, I see. The problem I have, however, is that my code *looks* like it would only close a position at the start of a new bar, but watching it trading live, I observed a position closed on a trailing stop intrabar. Here's my code example:

            protected override void Initialize()
            {
            Add(SMA(FastSMA));
            Add(SMA(SlowSMA));
            SetTrailStop("", CalculationMode.Ticks, TrailStop, false);

            CalculateOnBarClose = true;
            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
            // Condition set 1
            if (CrossAbove(SMA(FastSMA), SMA(SlowSMA), 1))
            {
            EnterLong(DefaultQuantity, "");
            }

            // Condition set 2
            if (CrossBelow(SMA(FastSMA), SMA(SlowSMA), 1))
            {
            EnterShort(DefaultQuantity, "");
            }


            Any ideas? Thanks so much for your help.

            Comment


              #7
              Yes, if that stop level is hit intrabar it would exit, as it's a real working order.

              Comment


                #8
                Is there a way I can have a trail stop close out a position ONLY at the first tick of the new bar?

                Comment


                  #9
                  Yes, but then you can't work with SetTrailStop(), you need to check the open tick begin greater / smaller than your trailstop value and then send an Exit() order.

                  Comment


                    #10
                    Great! Thanks again.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    633 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    364 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    105 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    567 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    568 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X