Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Breakeven and Trailing Stop Loss

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

    Breakeven and Trailing Stop Loss

    Hi everyone,

    I am stuck with an issue around trailing SL and breakevens and was hoping for some help.

    Code:
    ...
    protected override void OnBarUpdate()
            {
                if (BarsInProgress != 0)
                    return;
    
                if (CurrentBars[0] < 1)
                    return;
    
                 // Set 1
                if (
                     // My Strategy to determine the Long Entry
    
                   )
    
                {
                    EnterLongLimit(0,true, Convert.ToInt32(DefaultQuantity), (Low[1] - (Long_Negative_Offset_Arithmetic)) , @"LongTrade");
                }
    
            }
    Here is what I would like to achieve. Not being a programmer makes this a little tricky, as other forum posts somehow don't work for me.

    Condition 1: ASK is x ticks > entry price (example: "10")
    Action 1: Set static SL to entry price + y ticks (example: "2")

    Condition 2: ASK is z ticks > breakeven (example: "20")
    Action 2: Replace Static SL with trailing SL to breakeven + y ticks (example: "18", i.e. 20-2)

    Does anybody have an idea how I could do that?
    Thanks so much, learning a lot here!

    PS: the "Long_Negative_Offset_Arithmetic" is simply an adjustment to offset the limit entry price by the low of the previous bar - x ticks

    #2
    Originally posted by Oracletrades View Post
    Hi everyone, I am stuck with an issue around trailing SL and breakevens and was hoping for some help. Thanks so much, learning a lot here!
    Oracletrades Strategy Builder can be used to experiment with code.

    This thread has samples for B/E and trailing loss. You can open them in strategy builder and then do view code to copy and paste.

    Originally posted by 123r34 View Post
    I use the Strategy Builder as I am not a programmer. It would be very helpful if a Breakeven function was available in the Strategy Builder. When I test a trading idea manually the ATM Strategy easily allows a Breakeven setting. When I want to fine tune that idea in Strategy Builder Breakeven isn't available.. The Breakeven feature can really make a difference in the profitability of a strategy.

    Let me know if NinjaTrader has any interest in adding this feature.

    Thank you,

    Comment


      #3
      Hi Oracletrades, thanks for your note.

      Since you can not use SetStopLoss and SetTrailingStop together you must use SetStopLoss alone to modify the stop level. We have this example that shows how to modify your stop and target orders.



      Please let me know if I can assist any further.

      Comment


        #4
        Originally posted by JMont1 View Post

        Oracletrades Strategy Builder can be used to experiment with code.
        Yes, but I've made the leap into the unknown by customizing the code so there's no going back to Strat Builder (besides I want to learn!). Thanks anyway!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X