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

With the Strategy Builder, can we force it to exit all strategy positions when

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

    With the Strategy Builder, can we force it to exit all strategy positions when

    Hi folks,

    1. Could we make a Strategy Builder strategy be forced to exit all strategy positions upon enabling the strategy initially?

    and

    2. How can we with the Strategy Builder add in a condition to where no trades are taken if the NQ or ES futures is over plus +.50% or negative -.50% on the day?

    Thanks all!

    Greg

    #2
    Hello birdog,

    Thanks for your post.

    Are you referring to having the strategy start in a flat position when enabled?

    If so, you could create a condition in every Set in the strategy that is used to place an order that checks if the current State (Misc folder > Current state) is equal to State.Realtime (Misc folder > State > Realtime).

    This way the strategy will only place orders when processing real-time data.

    "How can we with the Strategy Builder add in a condition to where no trades are taken if the NQ or ES futures is over plus +.50% or negative -.50% on the day?"

    Please provide a brief description explaining exactly what you mean by this so I may accurately assist.

    Note that a limitation of Strategy Builder is that it is very limited in the mathematics it is able to do. Values such as prices or indicator values are only able to be offset by another value. For example, the PriorDayOHLC close price could be offset by 50 percent. This would likely require unlocking the strategy from the Strategy Builder and manually programming the logic yourself.

    I look forward to assisting further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      On 1. I will try that. Thanks.

      On 2. can it do the following in the Strategy Builder:
      If current price on the current day is greater than .50% on the day. Or, if current price on the current day is less than -.50% on the day. ?

      I would guess it could do this...

      Greg

      Comment


        #4
        Hello Greg,

        Thanks for your notes.

        To clarify, you want to check if the change from the Open of the session is now greater or less than 50% change. Is that correct?

        Say the current session's Open price is 1000 and the current market price is 1250. Are you wanting to calculate what that change is in percentage?

        This could likely be accomplished in the Strategy Builder using Custom Series which are created in the Additional Data screen of the Strategy Builder and applying custom mathematical logic by offsetting the Custom Series.

        Note that this would be complex to accomplish using the Strategy Builder and would be easier to calculate in an unlocked script. This is due to the limitation of math that the Strategy Builder is able to do.

        An increase could likely be detected by subtracting the current market price (Close[0]) from the session's Open price. Then, divide that number by the session's Open price and multiply the answer by 100. If the result is a negative number then this is a percentage decrease.

        A decrease could likely be detected by subtracting the session's Open price from the current market price. Then, divide that number by the session's Open price and multiply the answer by 100. If the result is a negative number then this is a percentage increase.

        I look forward to assisting further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          brandonhall

          To keep it even more simple, just something like when current bar closes on whatever instrument it is, I am looking for it to look at the % gain or loss at that moment when the bar closes of the ES or SPY on the day so far. Does that clarify more?

          I would prefer to stay in the Strategy Builder for this if we can for the moment on this question.

          Thanks again Brandon!

          Grewg

          Comment


            #6
            Hello Greg,

            Thanks for the clarification.

            To calculate the percentage change from the Open price of the current day to the current market price (Close) of any instrument, you would need to take the approach that was mentioned in post # 4.

            You could try creating Custom Series<double> variables in the Additional Data screen of the Strategy Builder and add custom mathematical logic using offsets to subtract the current day Open price from the current market price (Close[0]). Then, you would offset that value by dividing it by the current day Open price. Finally, multiply that number by 100 to get the percent change. If the result is a negative number then this is a percentage decrease.

            You could get the current day Open price from the Indicators folder > CurrentDayOHL > CurrentOpen. You could get the current market price from the Price folder > Close. Note that math could only be done using offsets in the Strategy Builder.

            Let me know if I may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              brandonhall Great...I will check it out. I have been playing with different setups and close. What you are describing will update on every bar close of the time frame the chart or strategy is on correct (not just one time at the open)? Just making sure...

              Regardless, I think I am pretty close here.



              Greg

              Comment


                #8
                Hello birdog,

                Thanks for your note.

                Yes, that is correct. This calculation would update at the close of each bar when the script is set to Calculate.OnBarClose.

                See this help guide page for information about Calculate: https://ninjatrader.com/support/help.../calculate.htm

                Please let me know if I may assist further.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_BrandonH View Post
                  Hello Greg,

                  Thanks for the clarification.

                  To calculate the percentage change from the Open price of the current day to the current market price (Close) of any instrument, you would need to take the approach that was mentioned in post # 4.

                  You could try creating Custom Series<double> variables in the Additional Data screen of the Strategy Builder and add custom mathematical logic using offsets to subtract the current day Open price from the current market price (Close[0]). Then, you would offset that value by dividing it by the current day Open price. Finally, multiply that number by 100 to get the percent change. If the result is a negative number then this is a percentage decrease.

                  You could get the current day Open price from the Indicators folder > CurrentDayOHL > CurrentOpen. You could get the current market price from the Price folder > Close. Note that math could only be done using offsets in the Strategy Builder.

                  Let me know if I may assist further.
                  brandonhall Could you send a few screenshots of what the strategy builder sections might look like? I am having trouble getting it just right I guess. Thank you. Greg

                  Comment


                    #10
                    Hello birdog,

                    Thanks for your note.

                    Please see the attached example script demonstrating how this could be accomplished by using Custom Series in the Strategy Builder.

                    Note that the script will print values to a New > NinjaScript Output window.

                    Let me know if I may assist further.
                    Attached Files
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      brandonhall Thumbs up. I notice the values are in the "Do the following" section in Set 1 with no Conditions and Actions above. If I were to add a simple example SMA cross over strategy and wanted to use it, what would it look like so that it only trades long if the current day is over .50% and short only under -50% on the day from the open?

                      Does the Do the following code fire even though there is no conditions and actions in the above?

                      Comment


                        #12
                        Hello birdog,

                        Thanks for your notes.

                        The example script simply calculates the PercentageIncrease value in the Actions section of the Conditions and Actions screen of the Strategy Builder since no conditions are required for calculating this value.

                        If you want to use the PercetageIncrease value for a condition in your strategy, a new Set (such as Set 2) would be created, your SMA crossover condition would be added to Set 2 and you would also create a condition in Set 2 that compares the PercentageIncrease custom series (Misc folder > Custom series > PercentageIncrease) to a Numerical Value of .50 or -.50 (Misc folder > Numerical value). Then call your Entry order method in the Actions section of Set 2 to place the order.

                        "Does the Do the following code fire even though there is no conditions and actions in the above?"

                        Yes, the Actions section of the Strategy Builder will fire at the close of each bar. The logic fires at the close of each bar since the example script's Calculate mode is set to OnBarClose. If there was a condition in the Conditions section of that Set, the Action would only fire at the close of each bar if the condition became true.

                        Please let me know if you have further questions on this.
                        Brandon H.NinjaTrader Customer Service

                        Comment


                          #13
                          brandonhall Thanks...we are close now I think. See this https://www.screencast.com/t/JEmoH2i4nDQ I have tested this without the PercetageIncrease and with. Without it, it trades on a particular days over 700 times on the 1 min (again just as testing). When I add PercetageIncrease it does not take any. I have also tried making the numeric value above 0. And, also different days with high percentage moves. Does the entry look correct to you? Here is the specific setup there for that condition https://www.screencast.com/t/hlvS20bb8epL

                          I am still working on it too and will let you know if I get it working.

                          Thanks so much Brandon!

                          Greg

                          Comment


                            #14
                            Hello birdog,

                            Thanks for your note.

                            If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true or the order is being ignored for other reasons.

                            To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

                            In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Also, add a print within the condition to place the order to ensure the logic is being reached.

                            Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

                            And, enable TraceOrders which will let you know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

                            Below is a link to a forum post that demonstrates how to use prints to understand behavior.

                            https://ninjatrader.com/support/foru...121#post791121

                            Please let me know if I may assist with creating a specific print or analyzing the output window results.​
                            Brandon H.NinjaTrader Customer Service

                            Comment


                              #15
                              brandonhall Ok. I was thinking I did not have the setup correct on it. So, it looks good to you here https://ninjatrader.com/support/foru...95#post1230895 right? I will keep testing and thanks for the trace info!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Jonker, Today, 01:19 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post Jonker
                              by Jonker
                               
                              Started by futtrader, Today, 01:16 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post futtrader  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              14 responses
                              1,789 views
                              0 likes
                              Last Post aligator  
                              Started by Jimmyk, 01-26-2018, 05:19 AM
                              6 responses
                              838 views
                              0 likes
                              Last Post emuns
                              by emuns
                               
                              Started by jxs_xrj, 01-12-2020, 09:49 AM
                              6 responses
                              3,294 views
                              1 like
                              Last Post jgualdronc  
                              Working...
                              X