Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Breakeven on strategy builder

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

    #16
    Hello Steve4616,

    Thank you for your post.

    If you want your Stop Loss to move to breakeven at the same moment as you reach 50 ticks in proft, it sounds like you will need to calculate OnPriceChange. When calculating OnBarClose, the logic within OnBarUpdate() in the strategy will only be called on the close for every bar. This means that the check to see if the price moved 50 ticks in your favor will only happen once per bar, and the strategy would not be able to check the price and move the Stop Loss intra-bar. For more information about the Calculate property:



    You mentioned that when you use OnPriceChange or OnEachTick, it results in a ton of entries being made. I would be curious about the conditions you are using to trigger entries, as well as whether you are using a signal name in your entry orders or not. There are internal order handling rules to prevent unwanted positions when using the Managed Approach in NinjaTrader, and the Strategy Builder strategies utilize the Managed Approach. The rules may be found here:



    There is some information about signal names on entry orders in the Strategy Builder here:



    As long as your entry orders have a signal name, if a condition to submit an entry is triggered and the signal name is not unique, the entry order will be ignored. Other tools you could keep in mind are the strategy settings for Entries per direction and Entry handling. The default settings may be set in the Strategy Builder on the "Default Properties" page, although the settings may be adjusted when adding the strategy to a chart or from the Strategies tab of the Control Center. When the entry handling is set to "AllEntries" then the strategy will process entry orders up until the number of Entries per direction is reached. If you have entry handling set to "UniqueEntries" then the strategy will process entry orders up until the number of Entries per direction is reached per each signal name.

    Here is a screenshot of where they may be found in the Strategy Builder:
    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


    Here is a screenshot of where they may be found when adding a strategy from a chart:
    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


    There are tools for testing and debugging the behavior of a strategy, even when developing in the Strategy Builder, such as Trace Orders and Print() statements. Trace Orders may be enabled from the "Default Properties" page of the Strategy Builder by expanding "More Properties" and checking the box for Trace orders. With this enabled, information about orders will be printed to the NinjaScript Output window (Control Center > New > NinjaScript Output). This allows you to confirm when orders are placed or when they are ignored and why. For more information about Trace Orders:





    For more information about using prints to debug your code, please see the following post and link to a video showing how to add prints in the Strategy Builder:





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

    Comment


      #17
      Originally posted by NinjaTrader_Emily View Post
      Hello Steve4616,

      Thank you for your post.

      If you want your Stop Loss to move to breakeven at the same moment as you reach 50 ticks in proft, it sounds like you will need to calculate OnPriceChange. When calculating OnBarClose, the logic within OnBarUpdate() in the strategy will only be called on the close for every bar. This means that the check to see if the price moved 50 ticks in your favor will only happen once per bar, and the strategy would not be able to check the price and move the Stop Loss intra-bar. For more information about the Calculate property:



      You mentioned that when you use OnPriceChange or OnEachTick, it results in a ton of entries being made. I would be curious about the conditions you are using to trigger entries, as well as whether you are using a signal name in your entry orders or not. There are internal order handling rules to prevent unwanted positions when using the Managed Approach in NinjaTrader, and the Strategy Builder strategies utilize the Managed Approach. The rules may be found here:



      There is some information about signal names on entry orders in the Strategy Builder here:



      As long as your entry orders have a signal name, if a condition to submit an entry is triggered and the signal name is not unique, the entry order will be ignored. Other tools you could keep in mind are the strategy settings for Entries per direction and Entry handling. The default settings may be set in the Strategy Builder on the "Default Properties" page, although the settings may be adjusted when adding the strategy to a chart or from the Strategies tab of the Control Center. When the entry handling is set to "AllEntries" then the strategy will process entry orders up until the number of Entries per direction is reached. If you have entry handling set to "UniqueEntries" then the strategy will process entry orders up until the number of Entries per direction is reached per each signal name.

      Here is a screenshot of where they may be found in the Strategy Builder:
      World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


      Here is a screenshot of where they may be found when adding a strategy from a chart:
      World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


      There are tools for testing and debugging the behavior of a strategy, even when developing in the Strategy Builder, such as Trace Orders and Print() statements. Trace Orders may be enabled from the "Default Properties" page of the Strategy Builder by expanding "More Properties" and checking the box for Trace orders. With this enabled, information about orders will be printed to the NinjaScript Output window (Control Center > New > NinjaScript Output). This allows you to confirm when orders are placed or when they are ignored and why. For more information about Trace Orders:





      For more information about using prints to debug your code, please see the following post and link to a video showing how to add prints in the Strategy Builder:





      Please let us know if we may be of further assistance.
      Thanks for this Emily. I don't use unique entry names which may be one of my biggest issues. As for the entry requirements and why it ends up being a ton of trades is because I use MA crossovers for entries, so when theres about to be a crossover, then every time there's a tick or 2 causing the crossover, it enters, but if there's a pullback of couple ticks, there's and exit, then entry again on the crossover and so on. Depending on the market conditions this can be 1 entry or 50 entries or even more if its particularly choppy and I'm using 100+ minute chart. Will using unique entry names stop this from happening?

      Comment


        #18
        Hello Steve4616,

        Thank you for your reply.

        Unique entry names alone may not prevent the specific scenario you described. If there is a crossover resulting in an entry, then the market moves against you and hits your exit, then moves back to a crossover causing another entry repeatedly, there isn't any logic to prevent the entries from occurring multiple times on the same bar. You could consider adding additional logic, such as BarsSinceEntryExecution() or BarsSinceExitExecution() that would check if a certain number of bars have passed since an entry/exit tied to a signal time was executed. This would allow you to use OnPriceChange for your calculation and get intra-bar breakeven updates as well as limit your strategy to only submitting one entry or exit per bar. You could also consider adding a bool variable that evaluates to True when you want the entry to be possible, then reset it to false after the entry is executed. Then another entry wouldn't be able to occur until the bool is True again.

        For more information about the concepts I have discussed and screenshots of where to find them in the Strategy Builder, please see the following links:Please let me know if I may be of further assistance.

        Comment


          #19
          Originally posted by NinjaTrader_Emily View Post
          Hello Steve4616,

          Thank you for your reply.

          Unique entry names alone may not prevent the specific scenario you described. If there is a crossover resulting in an entry, then the market moves against you and hits your exit, then moves back to a crossover causing another entry repeatedly, there isn't any logic to prevent the entries from occurring multiple times on the same bar. You could consider adding additional logic, such as BarsSinceEntryExecution() or BarsSinceExitExecution() that would check if a certain number of bars have passed since an entry/exit tied to a signal time was executed. This would allow you to use OnPriceChange for your calculation and get intra-bar breakeven updates as well as limit your strategy to only submitting one entry or exit per bar. You could also consider adding a bool variable that evaluates to True when you want the entry to be possible, then reset it to false after the entry is executed. Then another entry wouldn't be able to occur until the bool is True again.

          For more information about the concepts I have discussed and screenshots of where to find them in the Strategy Builder, please see the following links:Please let me know if I may be of further assistance.
          Thanks for this. I tried adding "BarsSinceEntryExecution" and then tried "BarsSinceExitExecution". I set both at "greater than 1" but then the strategy would not make any trades at all. Then I tried a bool, with "BarsSinceExitExecution> Greater than> 1 = Bool True. Then after long entry or and short entry, Bool = False. But it also will not make a trade with this setting. I knwo its friday and you're probably off for the weekend so I'm gonna search the forum to see if i can find out why. Hopefully I have it figured out by Monday, thanks again

          Comment


            #20
            Originally posted by Steve4616 View Post

            Thanks for this. I tried adding "BarsSinceEntryExecution" and then tried "BarsSinceExitExecution". I set both at "greater than 1" but then the strategy would not make any trades at all. Then I tried a bool, with "BarsSinceExitExecution> Greater than> 1 = Bool True. Then after long entry or and short entry, Bool = False. But it also will not make a trade with this setting. I knwo its friday and you're probably off for the weekend so I'm gonna search the forum to see if i can find out why. Hopefully I have it figured out by Monday, thanks again
            I figured it out, thanks!

            Comment


              #21
              Hello,

              Ive been working with this breakeven strategy trying to combine it to my strategy i have made. I have a few questions and am struggling in some areas. Just to make sure, (on the long AND short breakeven strategy you provided) do i put all my long conditions into the set 2 where it says "enter long" on the actions, then short conditions in the set 3 where it says "enter shor" in the actions

              also, Do i need to put stops and targets into the builder. or does the "initial stop distance" and "Target ticks" cover that?

              And i have 2 sets of long and short sets. to enter long at 2 different times when different sets of conditions are met. I tried to put the longs together. In the Long and short breakeven stategy you provided, there are 11 sets. Set 2 and 3 are for the entering long and short. I thought i should just duplicate the sets to make set 2 and 3 be 2 3 4 5, all the way to 13 instead of 11. and to keep them in order. So set 2 and 3 actions are dupicated to enter long and set 4 and 5 are duplicated to enter short. But in doing this i noticed the builder would automatically move those 2 sets back to the end. at Sets 12 and 13. Why is it doing this? I think i read somewhere that the set order matters.

              Ultimately im 99% sure a breakeven strategy would improve my strategy bc of the way it is built. however trying to do this, i cant get the results to be even half as good and im at a loss. I think i am doing something wrong.

              Any help is appreciated. thank you

              Comment


                #22
                Hello corvettecandles,

                Thank you for your reply.

                Yes, typically you would want to include all conditions in the set before the entry if you want all of those conditions to be evaluated before the action of going either long or short. The "initial stop distance" and "target ticks" do not fully cover the stops and targets; those values are used throughout the conditions and actions to eventually submit the exit orders in sets 8-11. These sets are configured on the "Conditions and actions" page of the builder and the "Stops and targets" page is not used for this strategy.

                If you are using multiple sets for long and short entries/exits, I suspect you will need to use unique signal names for the different possible entries and tie the exits to the signalName of the entry orders.

                To further understand and debug the behavior of your strategy, it can be useful to add Print() statements. We have more information, including a link to a video demonstrating how to add prints in the Strategy Builder, here:


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

                Comment


                  #23
                  So just to make sure im understanding.

                  you said the conditions need to go into the set BEFORE the enter long(set 2) or enter short(set 3). So you have conditions above the actions. but you mean put them in the conditions above set 1? not in the conditions above set 2 or 3? and if thats the case, the conditions i have for longs and shorts are different so how would i do that?

                  For now just forget about the multiple sets for each long and short. Lets just focus on having 2 sets for entries, 1 with its own conditions for longs, then 1 with its own conditions for shorts. In this case, for this strategy, where would i need to put the conditions for longs then where would i need to put the conditions for shorts. i assume i will need unique entry names. where do i put those?

                  secondly, where do i need to enter the stop and profit. i see what you are talking about in sets 8-11 but could you be specific to where exactly i need to enter the values?

                  Thank you so much for your help

                  Comment


                    #24
                    Hello corvettecandles,

                    Yes, if you are setting bools, double variables, or other variables that are checked in the conditions sets that place orders, these bools should be managed first, so the condition sets that manage the bools should be before the condition sets that check the state of the bools and trigger orders.

                    You can add two bools with different names, one for short and one for long. However, this wouldn't make too much sense as the strategy has only one position and can only be long or short, it can't be both. So you could use one variable for the bool or price which would just be set to the appropriate value.

                    For example if you have entryTriggered bool. You could set this to true from either entry condition set. Then require the bool to be false in those condition sets. Whether long or short, no new entries would be allowed until the bool is reset back to false.

                    where would i need to put the conditions for longs then where would i need to put the conditions for shorts.
                    You could put the condition set for short entries after the conditions for long entries if you wanted. Or you could put the conditions for short entries before long entries if you wanted. The condition sets should never be true at the same time, so it wouldn't really matter on the sequence in which the entry conditions were placed. That said, both entry conditions should be after any condition sets that are managing bools, doubles, or other variables.

                    i assume i will need unique entry names. where do i put those?
                    If you have multiple entries in the same direction, definitely use unique signalNames like longEntry1, longEntry2, etc. If you don't have multiple entries in the same direction you don't have to have to use unique signal names.

                    The Signal name field is set in the Actions window in the 'Order Management' section after selecting an order.

                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #25
                      i dont have any variables or inputs. i only have conditions and actions. im wanting to combine this breakeven strategy with mine. mine is much simpler so im just adding mine into the breakeven strategy.

                      so let me just back up a second. lets say my strategy has 2 sets: set 1 (conditions above and "enter long position" below) then set 2 (conditions above and "enter short position" below). Then i have stops and targets (profit target and stop loss).

                      Now i have the long and short breakeven strategy that i downloaded from you guys. How do i merge my strategy into this breakeven strategy? I just need to know where to put the conditions for the shorts, the conditions for longs, and the profit target, and stop loss.

                      Comment


                        #26
                        Hello corvettecandles,

                        You wouldn't be merging the example script into your script or the other way around. You would be learning how the logic works, how the variables are being set for the conditions, so that you can design your logic similarly to trigger similar behavior. This is a learning example. This not meant for you to stuff into your script.

                        You could put your entry conditions first if there are no variables to managed. I'm not certain how you are triggering a breakeven without using variables though..
                        The example we provided you uses variables for the StopPrice, TriggerPrice, and TriggerState.. So you wouldn't be using the example logic if you are not using variables..
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #27
                          so where is something that i can stuff into my script to make it breakeven?

                          jeez. The example you provided DOES have variables and inputs. MY strategy DOES NOT. im trying to merge MY strategy with YOUR breakeven (the one with variables and inputs).

                          Why cant you just tell me where to put the conditions and actions for longs or shorts. or how to link them to the inputs or variables? then where to put my profit and target.

                          thats all im trying to accomplish here. im one of who knows how many that just want a breakeven for my strategy.

                          Comment


                            #28
                            Hello corvettecandles,

                            To clarify, our examples are meant to be educational examples.

                            Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

                            That said, through email or on the forum we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

                            You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.​


                            That said, even though we are not intending for you to actually use the code that we writing and are expecting you to learn from the example so that you can design your own logic, you could decide to modify the example and add custom conditions for your entries. These would go before or in place of the the condition sets in the example that trigger EnterLong and EnterShort.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #29
                              i gotta say, this is a little ridiculous. im not asking for much. c++ isnt required for this and you know that.

                              i dont know why youre making this so difficult. what im asking is very simple. Theres no coding required lol.

                              how am i supposed to learn from the strategy when you wont even tell me where to put the conditions?? unbelievable

                              how do i get in contact with a professional NinjaScript Consultant

                              Comment


                                #30
                                or can i just request someone else to talk to?

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, 03-13-2026, 05:17 AM
                                0 responses
                                95 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                153 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                80 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                54 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                70 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X