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 Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        30 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        942 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        9 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by rocketman7, Today, 01:00 AM
        0 responses
        4 views
        0 likes
        Last Post rocketman7  
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        28 views
        0 likes
        Last Post wzgy0920  
        Working...
        X