Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Automatically moving stop loss based on price moving a number of ticks from entry.

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

    Automatically moving stop loss based on price moving a number of ticks from entry.

    Hi,

    I'm trying to implement a strategy that will automatically move my stop a couple of times based on price reaching a certain number of ticks away from entry. However, I'm struggling to do this in real time. My entry conditions are based on candle closes (On Bar Close in the default parameters in the strategy wizard), but the my stop moves should be based on real time price movements not only adjusted after candle closes.

    Is this something that is possible just via the wizard? If not, could you point me in the right direction for the kind of code I would need to edit to achieve this.

    Thanks,

    J


    #2
    This sounds like a trailing stop, does that not work? Trailing stop is ATM so it will update automatically on price movements, it's not tied to bar close like the strategy itself.

    If this doesn't work then you'd need to do this in the code but it's pretty simple.

    First you have to add a second Data Series at a higher resolution, such as 1 second or 1 tick. This you can do in the Strategy Builder.

    The next part would be including SL adjustment code within the strategy's OnBarUpdate method

    You'll need to update the threshold, Order Entry Name, and New Stop Loss Value, but below should be enough to get you there. You may also need to wrap your existing logic as shown.

    Code:
    void onBarUpdate() 
    {
        if(BarsInProgress == 0)
        {
    
                //Your original strategy code goes in here, this if block is executed on the Primary bars series
         }
    
    
    
       if(BarsInProgress == 1)
       {
               //This if block executed on the second bar series 
    
               if(Math.Abs(Close[0] - Position.AveragePrice) > (threshold)) 
               {
                        SetStopLoss("Order Entry Name", CalculationMode.Price, New Stop Loss Value, false);
              }
       }
    }






    Comment


      #3
      Hello J,

      Welcome to the NinjaTrader forums!

      Below is a link to an example of a breakeven and a trailing behavior in the Strategy Builder.


      Also, below is a link to a forum post with helpful resources on getting started with NinjaScript and C#. Please be sure to watch the 'Automate Your Trading with NinjaTrader's Strategy Builder' training video.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thanks for getting back to me. Appreciate the help!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        87 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        151 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        79 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        53 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        62 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X