Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Conditional Stop Loss

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

    Conditional Stop Loss

    Hi,

    Upon entering a position I want to set a stop loss for that trade based on a distance of 4 times the 10 day ATR from the price I entered at ; for example -" SetStopLoss(CalculationMode.Price, Position.AvgPrice - ATR(10)[0]*4); "

    On each bar update I then want to reset the stop loss using the same method (i.e. at a distance of 4 times the ATR from the new price) IF the trade has moved in my favour. However, if the trade has gone against me I want the stop loss to remain unchanged.

    I have placed the "StepStopLoss" method as described above in the OnBarUpdate () event in the same Condition Set where I enter the positions because the ATR is a dynamic value so I understand it has to be in OnBarUpdate and not in Initialize()????

    I have attached a screenshot of this, however, it does not appear to be working correctly in that the stop losses do not appear to be executing correctly, can you assist?

    In the screenshot you will notice that I have not yet inclued the logic to say only to update the stop loss if the position has moved in my favour; how do I do this? I was going to use something like on a long position - if (Close [1] < Close [0]) ....set the stop loss.........but this won't compile because it says I can't use "close" in this context when I use it in the OnBarUpdate ().

    Thanks,

    Ciaran
    Attached Files

    #2
    Hello ciaranfryan,

    Please see this reference sample for help on implementing this:
    Modifying the price of stop loss and profit target orders

    When using Position.AvgPrice you'll want to be sure that you set only when you are in a position. You'll then reset (not use Position.AvgPrice) when you are flat.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ciaran,

      I'm wondering what the basis is for your 4x10ATR stop loss strategy?

      Prior to seeing your post, I was contemplating implementing something similar, but based on standard deviation. Sort of, a way to filter noise from the signal (S/N ratio).

      Thanks,

      borland

      Comment


        #4
        Hi Borland,

        I like the ATR indicator as a method for setting stop losses because I think it's a good measure of recent volatility of the instrument and can provide a good location for positioning a stop loss that will not be shaken out by "noise". To be frank though; at this point I'm simply trying to get more proficient at coding c# so I can effectively test and implement my strategies; I have no particular evidence that 4* the 10 day ATR is a better stop loss than any other.

        Regards,

        Ciaran

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        368 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        571 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X