Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Request Breakeven Functions in Strategy Builder

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

    #16
    Hello Chelsea,
    I have noticed that I have mixed up breakeven and trailing. I apologize for this. I am having also some difficulties in understanding how to reaplce tick values as user inputs for stop, target, and trailing, with percent values as user inputs. I have to review back the script changes I made. Thank you for your patience and assitance.

    Comment


      #17
      Hello guidoisot,

      As example you can have a double variable used as an input.

      [Range(1, double.MaxValue), NinjaScriptProperty]
      [Display(Name = "DistancePercentInput", GroupName = "NinjaScriptParameters", Order = 0)]
      public double DistancePercentInput
      { get; set; }

      Set the default value for this in State.SetDefaults.
      DistancePercentInput = .5;

      Then supply this to SetStopLoss().

      SetStopLoss(CalculationMode.Percent, DistancePercentInput);

      https://ninjatrader.com/support/help...etstoploss.htm
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Hello Chelsea,
        I do not understand why after some trades the sample breakeven posted does not trigger neither the SL nor the BE.
        Please see attached image where the script is applied to RTY

        Thanks.

        Click image for larger version  Name:	RTY no breakeven stop.JPG Views:	1 Size:	292.6 KB ID:	1045442
        Last edited by guidoisot; 01-16-2019, 08:16 AM.

        Comment


          #19
          Hello guidoisot,

          I am responding on behalf of Chelsea who is out of the office today.

          These sorts of order submission behaviors with strategies will involve taking debugging steps to see why the orders have not been submitted. We can see the bar the strategy goes long after the bar where the order submission tok place. This bar where we see the execution marker will be the bar where the stop will be submitted. Processing historical data is always done with Calculate.OnBarClose, so backtesting in the Strategy Analyzer will always process the script logic in this fashion unless Tick Replay is used and another Calculate mode is forced in the strategy.

          Since we are processing on bar close, the close of the bar where we see the execution marker will be the Close[0] used when submitting the stop.

          For the first case, the bar did have a High 81 ticks up, but the strategy uses Calculate.OnBarClose so the order was submitted after the bar had climbed 81 ticks. Having the strategy calculate OnPriceChange or OnEachTick will have Close[0] update intrabar and allow the strategy to submit the order midbar. This would have allowed for the breakeven to be triggered. We don't see the initial stop for the same reason as the second case.

          For the second case, the stop was submitted a specific distance below the Average Entry Price and since this was processed on the next bar, the stop was submitted to an invalid level which is noted when enabling TraceOrders.

          To debug issues like this with your scripts, TraceOrders should be used to display issues with order submission in the output window. Since backtests pass over many bars at once, I would recommend opening the data box on the Strategy Analyzer Chart and enable Bar Indexes. You can then go back to the strategy code and add prints when CurrentBar equals that bar so you can identify specific information about what is going on in the strategy.

          Publicly available information for debugging tips are linked below.

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

          Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

          Debugging with the Strategy Builder - https://www.screencast.com/t/8uvjfM8h

          Please let us know if you haven any additional questions.
          Last edited by NinjaTrader_Jim; 01-16-2019, 03:18 PM.
          JimNinjaTrader Customer Service

          Comment


            #20
            Thank you. Debugging is definetly a methodology a beginner as myself should learn! Regarding this breakeven script, I understand that it is an issue raising when there is a too wide open-to-close range for the first bar on the trade (unfortunately IB data are not tick by tick) . In the meantime I have been testing various inputs and in order to compensate for these not too frequent wide range 1st bars I am attaching to the script a wide stop: 350 in the sample test attached (either a stop loss or a trailing, I am not sure yet what works better). I am testing this method on a set of main futures and "IN THEORY" the first results do not look too bad (attached is print from the analyzer). A solution perhaps is in finding a way to tell the builder to treat the first bar in the trade in a different way from the following ones, but I have not yet figured out anything about this. Finally, with regard to this breakeven and/or trailing approach, another thing I wish to look at is attaching an ATM by unlocking the strategy created on the Builder. Thank you to both of you.

            Click image for larger version

Name:	analyzer printout.JPG
Views:	1516
Size:	286.6 KB
ID:	1045484

            Comment


              #21
              Hello guidoisot,

              The main issue is the strategy is backtested with Calculate.OnBarClose and the stop is submitted to a level that becomes invalid once the first bar closes. If you enable Tick Replay and force the strategy to use another Calculate mode, OnBarUpdate will update on the price change or on a new tick which would submit the order at an appropriate level before that bar closes and the order's price level becomes invalid.

              I edited my previous post for more clarity.

              If you would like to still have the strategy use OnBarClose and not worry about using Tick Replay, I would recommend using our OnExecutionUpdate() method to submit your target and stop.

              An example that demonstrates using OnExecutionUpdate and moving the Stop Loss is linked below. This example is publicly available.

              SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

              I look forward to being of further assistance.
              JimNinjaTrader Customer Service

              Comment


                #22
                • please add my vote for this feature request ID#SFT-2212
                  Thank you.

                Comment


                  #23
                  Hello DTSSTS,

                  I've added a vote on your behalf. Thanks for sharing interest.
                  JimNinjaTrader Customer Service

                  Comment


                    #24
                    Originally posted by NinjaTrader_Jim View Post

                    Debugging with the Strategy Builder - https://www.screencast.com/t/8uvjfM8h
                    please can you let me know why from the attached strategy there are no prints on the output window of the platform?
                    I can see the plots "Trend Dots" and "Trend Bars" of the indicator in the chart "Data Box" , so I understand they should be printed.



                    Thank you.
                    Attached Files

                    Comment


                      #25
                      Hello guidoisot,

                      The Data Box will show values for plots and Open, High, Low, Close values for the Data Series. These values will reflect where your mouse cursor is. I recommend using the Crosshair when using the Data Box. The Data Box can also have Bar Indexes and Bars Ago indexes added which can help with NinjaScript development. These can be enabled when right clicking on the data box.

                      Prints are displayed in the NinjaScript Output window, and I don't see this window open in your screenshot. A NinjaScript Output window can be opened by selecting New > NinjaScript Output from the Control Center. Any prints that are reached will then be displayed in the Output window. If you are not seeing prints, I would suggest to check for errors in the log tab of the Control Center and to check the logic to make sure the prints can be reached.

                      Let us know if there is anything else we can do to help.
                      JimNinjaTrader Customer Service

                      Comment


                        #26
                        Please add my YES to NT8
                        SFT-2212

                        Comment


                          #27
                          JMont1,

                          Thanks! Vote added!
                          Josh G.NinjaTrader Customer Service

                          Comment


                            #28
                            NinjaTrader_ChelseaB Attempted to duplicate NT8 MA crossover with the Break Even and Trail Stops. Truly would like to use the same Stop Market order in your examples but for some reason they do not trigger. Set7 & 8 both should use the stop market that is listed as first exit. Unfortunately since they do not seem to fire I backed them up with Stop Limit orders under a different name to distinguish which one fires.

                            If the second limit orders are removed the stop market still does not fire.

                            May I request you test to ensure Strategy Builder's stop market order is working correctly? Thank you.
                            Last edited by JMont1; 07-21-2019, 06:04 AM.

                            Comment


                              #29
                              Hello JMont1,

                              To confirm the issue is stop limit orders are not being submitted?

                              Are you receiving an error message?
                              (If so what is the error message?)
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #30
                                Originally posted by NinjaTrader_ChelseaB View Post
                                Hello JMont1,

                                To confirm the issue is stop limit orders are not being submitted?

                                Are you receiving an error message?
                                (If so what is the error message?)
                                NinjaTrader_ChelseaB No errors just does not execute. Have updated the strategy to better view what is happening but still does not work on StopMarket or even StopLimit also. So I have a Plain old Exit Long Position as the third action in the step for both BreakEven and TrailStop steps.

                                If you remove the final exit, neither of the other exit types are working. Thank you for taking a look.

                                Sunday 3pm update: Removing script to update iit again.
                                Last edited by JMont1; 07-21-2019, 01:08 PM.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by fernandobr, Today, 09:11 AM
                                0 responses
                                0 views
                                0 likes
                                Last Post fernandobr  
                                Started by itrader46, Today, 09:04 AM
                                1 response
                                3 views
                                0 likes
                                Last Post NinjaTrader_Clayton  
                                Started by timmbbo, Today, 08:59 AM
                                0 responses
                                2 views
                                0 likes
                                Last Post timmbbo
                                by timmbbo
                                 
                                Started by bmartz, 03-12-2024, 06:12 AM
                                5 responses
                                33 views
                                0 likes
                                Last Post NinjaTrader_Zachary  
                                Started by Aviram Y, Today, 05:29 AM
                                4 responses
                                14 views
                                0 likes
                                Last Post Aviram Y  
                                Working...
                                X