Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
      Chris L.NinjaTrader Customer Service

      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 GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,227 views
        0 likes
        Last Post xiinteractive  
        Started by andrewtrades, Today, 04:57 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        7 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        440 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        12 views
        0 likes
        Last Post FAQtrader  
        Working...
        X