Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Breakeven on strategy builder

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

    Breakeven on strategy builder

    Please help me add a breakeven stop to a trategy developed on the builder, im not good with programming...ive tried something like Current Ask greter/equal positian.average.price(+15)
    then...exitLONG as a sTOP order, and on the price i set average.position.price -15 but the order doesnt happen .... if i insted just put exit long, as soon as it hits 15 points it automatically exit the position, but i want the order to be placed 15 points bellow(breakeven point)...can you help?

    #2
    Hello Vinnypoker,

    Thank you for your post.

    I'm attaching a simple example showing how to create a stop order that moves to breakeven after a specific number of ticks in profit in the Strategy Builder.

    Please let us know if we may be of further assistance to you.
    Attached Files

    Comment


      #3
      Thank you for the reply, it is exactly what i wanted, BUT im having trouble understanding the conditions, is there any way they can be explained?
      thank you

      Comment


        #4
        Hello Vinnypoker,

        Thank you for your reply.

        Basically how this works is that it runs off a TriggerState variable that is set to 0, 1, 2 or 3 depending on where we are in the trade.

        The first set, set 1, will simply reset our TriggerState to 0 when the position is flat and we've had a prior trade. This allows us to take further trades after the initial trade.

        Set 2 basically just says if you are in a flat position, set the TriggerState to 1 and enter a long entry.

        Set 3 says that if we are in a long position and our TriggerState is 1, meaning an entry order was submitted, we change the TriggerState to 2 and assign values for the initial stop value as well as the value at which we want to move the stop to breakeven.

        Set 4 checks if we have set our stop and target values by ensuring that the TriggerState is 2 and if the current price is greater than or equal to our TriggerPrice (the level the current price must reach before the stop is moved to breakeven). If it is, we set TriggerState to 3, assign the Average position price to StopPrice, and draw a diamond drawing object on the chart on the current bar so you know on what bar the stop changed.

        Finally, Set 5 is where the stop is actually placed/updated. If the trigger state is 2 or greater, the stop will be placed or modified to the stop price saved in our StopPrice variable.

        Please let us know if we may be of further assistance to you.

        Comment


          #5
          so basically all this Tabs correspond to 1 long trade! What i needed is a simple...."if my long trade is 15 points above entry, a breakeven buystop is added to the entry price! simple as that"

          Comment


            #6
            Hello Vinnypoker,

            Thank you for your reply.

            The two user inputs for the example strategy control A) How far from the initial entry the stop would be placed (InitialStopDistance) and B) at how many ticks in profit the stop should be moved to breakeven (BreakEvenTrigger). These are in ticks in this example. For most futures, there are 4 ticks per point, so you'd multiply 15 * 4 = 60 and set the BreakEvenTrigger value to 60. You can set the InitialStopDistance value to however many ticks below the entry you like.

            Please let us know if we may be of further assistance to you.

            Comment


              #7
              Hey Kate, thanks again for your help, i was able to add the tabs to my strat, the diamond does pop out at the value i put but the exit once the price comes back bellow entry doesnt happen, do you guys assist remotely?

              Comment


                #8
                Hello Vinnypoker,

                Thank you for your reply.

                So you're aware, we cannot provide one on one educational services for NinjaScript over the phone. We cannot assist with debugging over the phone. We cannot assist with building a strategy in the Strategy Builder over the phone.

                NinjaScript strategies, even those in the Strategy Builder are complex and have many more moving parts than what is set up in your Conditions and Actions. As we cannot feasibly educate you on all of the ins and outs with NinjaScript over the phone, we cannot provide hands on demonstrations as we need to ensure you are fully disclosed on how to build and troubleshoot NinjaScript strategies. Even simple conditions that seem obvious may encounter corner cases when deployed live. We also These cases can be understood and our Scripting Support team is here to help, but for these reasons, we cannot provide this sort of hands on support.

                That being said, if you provide the current strategy I'm happy to take a look and see if I see the same behavior. You can export a strategy from Tools > Export > NinjaScript Addon. Do not check the box to export as a compiled assembly or I will not be able to review your logic. Please attach the resulting .Zip file to your reply.

                Thanks in advance; I look forward to assisting you further.

                Comment


                  #9
                  Hello Vinnypoker,

                  Thank you for your reply.

                  Focusing just on the breakeven functionality, you would want to put set 26 before set 24, or the stop wouldn't move until the next bar. I would suggest if you're not seeing the orders you would expect to, the first thing I would recommend would be to turn on the Order Trace function:

                  Strategy Builder > Default Properties > More Properties > Trace Orders, or:

                  Once you then recompile the strategy, you can open a new NinjaScript Output window under New > NinjaScript Output. This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders. You can then look through and see what may be occurring.

                  Here is a link to our help guide that goes into more detail on tracing orders:

                  https://ninjatrader.com/support/help...aceorders2.htm

                  Trace orders alone may not give you the full picture of whether or not a trade should have been entered on a given bar, so adding prints to your strategy that will show in the NinjaScript Output window, with information on what the variables you're using for your conditions are on a particular bar, can be helpful.

                  This forum post goes into great detail on how to use prints to help figure out where issues may stem from — this should get you going in the correct direction. You can even add these using the Strategy Builder.

                  https://ninjatrader.com/support/foru...ns-not-working

                  If you run into issues like we saw here, the above information will allow you to print out all values used in the condition in question that may be evaluating differently. With the printout information you can assess what is different between the two.

                  Please let us know if we may be of further assistance to you.

                  Comment


                    #10
                    Kate i was able to do it! thanks, the only question i have...do i need to make a separate strategy for long and another for short? also, you sent an example of a long trade, can you send one with a short trade? just to make sure my inputs are right! thanks (the reason it was not working before, is because i had a profit target already set, and with that it wasnt allowing the breakeven trade to happen)

                    Comment


                      #11
                      Hello Vinnypoker,

                      Thank you for your reply.

                      You'd want to have both the long and shorts in the same strategy so it can manage the entire position on the instrument. I've attached an example that builds upon that BreakEvenBuilder example and has both long and short logic.

                      Please let us know if we may be of further assistance to you.
                      Attached Files

                      Comment


                        #12
                        Hello Kate
                        I am trying tto use the LongShortBreakEvenBuilderExample.
                        I added the code to a strategy builder but received an error message.
                        Can you help with what I have done wrong? Screenshots attatched.
                        Thank you

                        Comment


                          #13
                          Hello Richard415,

                          Thank you for your reply.

                          You've unlocked the code from the Builder and copied it into another script incorrectly.

                          I would suggest reimporting so the code will be locked to the Strategy Builder again. Once you've reimported it, you can open a Strategy Builder window, select LongShortBreakEvenBuilderExample, and use the Builder navigation to move through the Builder screens so you can review how that's set up and add your own conditions or actions if you like.

                          Please let us know if we may be of further assistance to you.

                          Comment


                            #14
                            Hello Kate
                            Thank you for your fast response. I will try your recommendation.

                            Comment


                              #15
                              Originally posted by NinjaTrader_Kate View Post
                              Hello Vinnypoker,

                              Thank you for your reply.

                              You'd want to have both the long and shorts in the same strategy so it can manage the entire position on the instrument. I've attached an example that builds upon that BreakEvenBuilder example and has both long and short logic.

                              Please let us know if we may be of further assistance to you.
                              Hi Kate,
                              To confirm, will this work on "OnBarClose"? Also, will it update on the entry bar? I have messed around for months with the long only version, and created the short side myself but can never get it to work if the trade goes against on the first bar. Also, if i set a SetStopLoss then it gets messed up too. I can't figure out how to get OnPriceChange or OnEachTick to work without making a ton of entries each time the condition comes true so I only use OnBarClose, however, with the long breakeven version, if the trade goes against me on the first bar, then I'm left with no stop which is not good.
                              For reference, I generally use higher timeframe charts(100-300minute) with small targets(100 ticks), and on a 100 minute bar, often I'll hit the target on a long but can still close as a red candle because anything can happen in that length of time. I just want the trade to enter a breakeven stop after being up say 50 ticks, so I don't have as many losing trades. Thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, 03-13-2026, 05:17 AM
                              0 responses
                              86 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
                              52 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              59 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X