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

Autobreak even for strategy builder

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

    Autobreak even for strategy builder

    Hi I have a strategy i would like to add an autobreak even triggered at 20 ticks and the stop loss is moved from -24 ticks to +8 ticks. is this possible?

    #2
    Welcome to the forums henryd333!

    This is possible to do with the Strategy Builder, however it must be done with your own logic using Exit methods in the Conditions and Actions page of the Strategy Builder. The Stops and Targets section of the Strategy Builder is intended for static stops and targets.

    I have attached a couple examples that can demonstrate making breakeven logic.

    Please note that Conditions and Actions is processed based on the Calculate Mode of the strategy, so the price may move greater than the distance needed to trigger the update if you are using Calculate.OnBarClose. You may use Calculate.OnPriceChange for intra bar order logic, but keep in mind that historical processing/backtesting will be forced to use Calculate.OnBarClose behaviors as there is no intrabar movement with historical data.

    We look forward to assisting.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you Jim, I´ll check the examples.

      Comment


        #4
        Hi Jim

        Do you know if it is possible to create a strategy that triggers on bar close and the auto break even works on ticks?
        Do you have a code as an example for that?

        Comment


          #5
          Hello henryd333,

          I do not have an example for this specifically, and it also will require unlocking the code.

          You would then have to use IsFirstTickOfBar to identify when a bar has closed so you can differentiate logic that should occur on bar closes versus on price changes. When using OnEachTick/OnPriceChange we are working with the developing bar instead of the bar that has just closed, so on the first tick of a new bar we would use BarsAgo 1 references to reference the bar that had just closed.

          IsFirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm

          Example for creating OnBarClose like logic using OnEachTick/OnPriceChange - https://ninjatrader.com/support/help...either_cal.htm

          If you are not familiar working with unlocked NinjaScript strategies, I suggest viewing the NinjaScript Editor 401 tutorial.

          NinjaScript Editor 401 (publicly available recording) - https://www.youtube.com/watch?v=H7aDpWoWUQs

          We look forward to assisting.
          JimNinjaTrader Customer Service

          Comment


            #6
            Thank you!

            I could make the autobreakeven thanks to your example, but i need the exact price that the order is placed, I used close(0) to calculate the stop, but is way far from the entry point, is there any name that calls the entry price of an actual order?

            Comment


              #7
              Hello henryd333,

              I use Position.AveragePrice to get the average entry price of the strategy's position in the examples. (Conditions > Strategy > Average position price)

              If you would like to retrieve the average entry price of a specific order, this will require unlocking the code and using OnOrderUpdate to track Order objects. You could then get average entry price of the Order object from the Order.AverageFillPrice property. Otherwise you may try saving the stop price or limit price of your orders to variables, but this will not be the same thing as the fill price of the order.

              The example below shows how Order object tracking can be done with OnOrderUpdate, as well as how you can submit orders for target/stop from OnExecutionUpdate.

              SampleOnOrderUpdate - https://ninjatrader.com/support/help...nt8/?order.htm

              Please let us know if you have any additional questions.


              JimNinjaTrader Customer Service

              Comment


                #8
                Hello NT Jim,

                I appreciate your post(s) as they're on topic for me. I'm trying to find a method to enable/utiilize an autobreakeven and more importantly an autotrail type of
                stop into my strategy.. I use that type of custom stop in my manual trading and find it very useful..

                If its not too much too ask, when you provide the link to view the 'strategy builder' conditions and actions - could you clarify which 'Set' these conditions should
                be in ?

                My strategy(ies) employ 'Set1' for long entry.. 'Set2' for short entry.. 'Set3' for long exit..and 'Set4' for short exit.. Will these conditions work with that type of 'Set'
                arrangement.. If not how should I arrange the 'Sets' ?

                I appreciate your help finding this information and especially your advice on where to put the conditions when trying to use them..

                cheers,

                Comment


                  #9
                  Originally posted by Chuck_63 View Post
                  Hello NT Jim,

                  I appreciate your post(s) as they're on topic for me. I'm trying to find a method to enable/utiilize an autobreakeven and more importantly an autotrail type of
                  stop into my strategy.. I use that type of custom stop in my manual trading and find it very useful..

                  If its not too much too ask, when you provide the link to view the 'strategy builder' conditions and actions - could you clarify which 'Set' these conditions should
                  be in ?

                  My strategy(ies) employ 'Set1' for long entry.. 'Set2' for short entry.. 'Set3' for long exit..and 'Set4' for short exit.. Will these conditions work with that type of 'Set'
                  arrangement.. If not how should I arrange the 'Sets' ?

                  I appreciate your help finding this information and especially your advice on where to put the conditions when trying to use them..

                  cheers,
                  Hello Chuck,

                  Thank you for your note.

                  This has also been discussed in other threads, including the following which has a post from another colleague that includes examples demonstrating both breakeven and auto trail built in the strategy builder:


                  To view the sets of conditions and actions, you may import the examples into your platform with the following steps:
                  • Download the example(s) from the forum post
                  • In the platform, go to Control Center > Tools > Import > NinjaScript AddOn
                  • Select the downloaded .zip folder to import
                  • Once the import is successful, go to Control Center > New > Strategy Builder
                  • Select the newly imported strategy from the dropdown menu
                  You should now be able to click through the Strategy Builder screens and view how the different sets are configured on the Conditions and Actions screen. In order to incorporate your entry and exit logic, I suggest testing along the way. It can be helpful to start small and only add in the logic for entering/exiting in one direction first. Once that is working as expected, you can add in additional sets for the entries/exits in the opposite direction.

                  Please let us know if we may be of further assistance.
                  Emily C.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Emily,

                    Great, yes - I've visited this thread lately and downloaded the examples. I'll take your advice to 'test along the way' because my last tries weren't
                    successful. If I may ask to be sure - am I correct to assume the examples are coded to work with long positions only as written ? If so, should the commands
                    work with the values given changed to negative numbers while keeping the same number values for short positions.. ?
                    Last edited by Chuck_63; 03-30-2023, 12:48 PM.

                    Comment


                      #11
                      Hello Chuck,

                      Thank you for your reply.

                      Yes, the examples only deal with long positions as they are currently written. The BreakevenBuilderExample uses values for TriggerState, BreakevenTrigger, and InitialStopDistance. You will likely need to add additional conditions that use different TriggerState values for a short position, as well as potentially having a positive value for PositiveBreakevenTrigger and a negative value for NegativeBreakevenTrigger and then a negative InitialLongStopDistance and a positive InitialShortStopDistance to keep the values so that the offsets are on the correct side of the market depending on whether you go long/short. For more information about offsetting an item's value:


                      The TrailBuilderExample has Set 3 that checks if the position is Long and if the Close price is greater than the CurrentTriggerPrice, which is a positive value. For a set that checks if the condition is short, you are correct that you will likely need to use negative numbers to add a condition that checks if the position is short and if the Close price has gone below the trigger price in the opposite direction compared to how it is checked for the long position.

                      Please feel free to reach out with any additional questions or concerns.
                      Emily C.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_Jim View Post
                        Welcome to the forums henryd333!

                        This is possible to do with the Strategy Builder, however it must be done with your own logic using Exit methods in the Conditions and Actions page of the Strategy Builder. The Stops and Targets section of the Strategy Builder is intended for static stops and targets.

                        I have attached a couple examples that can demonstrate making breakeven logic.

                        Please note that Conditions and Actions is processed based on the Calculate Mode of the strategy, so the price may move greater than the distance needed to trigger the update if you are using Calculate.OnBarClose. You may use Calculate.OnPriceChange for intra bar order logic, but keep in mind that historical processing/backtesting will be forced to use Calculate.OnBarClose behaviors as there is no intrabar movement with historical data.

                        We look forward to assisting.
                        Hi Jim, Why can't we apply the BE stop after applying static stop & target under "Stops and Targets" screen in strategic builder?
                        So my strategy currently has 3 sets under "Conditions & Actions".
                        Set 1 is to Enter Short if some conditions match.
                        Set 2 is to Enter Long if some conditions match.
                        Set 3 is to Exit Short if some conditions match.
                        Set 4 is to Exit Long if some conditions match.

                        And since i added "SetProfitTarget" and "SetStopLoss" in "Stops and Targets" screen, i am assuming that after Set 1 or Set 2 executes, the profit target and stop loss are placed on my chart immediately, right?


                        And if so, why can't i move my stop to BE or "BE + few ticks" if the price moves above/below certain ticks but haven't met my Profit target yet?
                        Last edited by psangram; 01-07-2024, 08:00 AM.

                        Comment


                          #13
                          Originally posted by psangram View Post

                          Hi Jim, Why can't we apply the BE stop after applying static stop & target under "Stops and Targets" screen in strategic builder?
                          So my strategy currently has 3 sets under "Conditions & Actions".
                          Set 1 is to Enter Short if some conditions match.
                          Set 2 is to Enter Long if some conditions match.
                          Set 3 is to Exit Short if some conditions match.
                          Set 4 is to Exit Long if some conditions match.

                          And since i added "SetProfitTarget" and "SetStopLoss" in "Stops and Targets" screen, i am assuming that after Set 1 or Set 2 executes, the profit target and stop loss are placed on my chart immediately, right?


                          And if so, why can't i move my stop to BE or "BE + few ticks" if the price moves above/below certain ticks but haven't met my Profit target yet?
                          When set 1 or set 2 executes, do we NOT have hold of the stop & PT set at that time?
                          If we do have hold of those values, then all we can do is add another set-5 for short and set-6 for Long .
                          And in Set-5, check if current price is greater than or equal to "ShortBreakEvenTrigger" ticks from the average position size, move the Stop to average position size? (Also, my question here is how to move the existing stop to a different price? (can this be done in NT strategy)?

                          Comment


                            #14
                            Originally posted by psangram View Post

                            When set 1 or set 2 executes, do we NOT have hold of the stop & PT set at that time?
                            If we do have hold of those values, then all we can do is add another set-5 for short and set-6 for Long .
                            And in Set-5, check if current price is greater than or equal to "ShortBreakEvenTrigger" ticks from the average position size, move the Stop to average position size? (Also, my question here is how to move the existing stop to a different price? (can this be done in NT strategy)?
                            Also, to let you know - i only take one position at a time, meaning either 1L or 1S and exit that at TP or SL or with a closing order. Then take next Long or short.

                            Comment


                              #15
                              Originally posted by psangram View Post

                              Hi Jim, Why can't we apply the BE stop after applying static stop & target under "Stops and Targets" screen in strategic builder?
                              So my strategy currently has 3 sets under "Conditions & Actions".
                              Set 1 is to Enter Short if some conditions match.
                              Set 2 is to Enter Long if some conditions match.
                              Set 3 is to Exit Short if some conditions match.
                              Set 4 is to Exit Long if some conditions match.

                              And since i added "SetProfitTarget" and "SetStopLoss" in "Stops and Targets" screen, i am assuming that after Set 1 or Set 2 executes, the profit target and stop loss are placed on my chart immediately, right?


                              And if so, why can't i move my stop to BE or "BE + few ticks" if the price moves above/below certain ticks but haven't met my Profit target yet?
                              In the Strategy Builder, you may not modify the prices of order submitted via the Stops and Targets screen. To phrase that differently and confirm one of your questions, no you do not "have hold" of the stop loss and profit target in your Conditions and Actions sets. Once those orders are submitted from Stops and Targets, they may not be modified from the Conditions and Actions screen. You must use Exit orders in the Conditions and Actions if you would like to create a breakeven scenario in the Strategy Builder. Exit actions may not be combined with Stops and Targets due to the internal order handling rules listed here - for example, if there is an order from SetStopLoss() or SetProfitTarget() and Exit() orders in the Actions, one of those orders will be ignored:
                              https://ninjatrader.com/support/helpGuides/nt8/index.html?managed_approach.htm#InternalOrderHandl ingRulesThatReduceUnwantedPositions

                              Code:
                              https://ninjatrader.com/support/helpGuides/nt8/index.html?managed_approach.htm#InternalOrderHandlingRulesThatReduceUnwantedPositions
                              You can modify stops and targets from the Set() methods if you configure them dynamically in OnBarUpdate() within an unlocked script in the NinjaScript Editor. This is not an option in the Strategy Builder because it uses static stops and targets that are set in State.Configure. For an example of an unlocked script that can modify to breakeven:


                              Please let us know if we may be of further assistance.
                              Emily C.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by trilliantrader, Today, 08:16 AM
                              2 responses
                              6 views
                              0 likes
                              Last Post trilliantrader  
                              Started by samish18, Today, 08:31 AM
                              1 response
                              1 view
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by Creamers, 09-08-2023, 10:26 AM
                              6 responses
                              157 views
                              0 likes
                              Last Post JonyGurt  
                              Started by funk10101, Today, 08:14 AM
                              1 response
                              2 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by bill2023, Yesterday, 08:51 AM
                              3 responses
                              22 views
                              0 likes
                              Last Post bltdavid  
                              Working...
                              X