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

Adding entry condition to the TrailBuilderExample

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

    Adding entry condition to the TrailBuilderExample

    I liked so much how the example trail builder worked that I attempted to add a condition for entry. Here is a side-by-side comparison from original to mine. Where may I be corrected in my thesis?
    Attached Files

    #2
    Hello trdninstyle,

    That sample won't work to use a limit order as the entry order because it will expire after 1 bar. The reason that the last set in that example uses a variable is so the last set remains true to keep the order alive. To make a limit entry you would have to make the entry condition remain true until the order is filled. To maintain how that sample works you would need to use a market entry. You would otherwise need to make your own new variables/sets to control keeping the entry order active until filled.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Because of the trailing stop and to have it trigger, I still need to keep those two variables, the current trigger price & current stop price, right? But add two more variables, like trigger price & trigger state? Like I have over in my other strategy where I'm using the trailing stop.

      The reason I came back to just that trailing stop example was because the stop kept moving away from price on me & back down into negative territory instead of just being stopped out with a small profit or small loss. I assumed I got too complicated with my 22-set strategy & noticed that the example one that I had was doing the same thing, so I re-downloaded it & the stop worked properly. So, I wanted to keep that simple trailing behind price idea & add a set of conditions.

      Sorry that 2nd paragraph was long.
      Attached Files

      Comment


        #4
        To use a limit order do I need to implement 5 sets? Also, I need to add a StopPrice variable.

        Unless I stay with my 22-set strategy and try to get my stop from running away from price until it's turns into a losing trade after it's been profitable!


        I have the trailing set at 5 and 5 like the trail example. Stop doesn't stay at -5 ticks keeps moving back.

        Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


        And a while later still in that same trade where it should have been stopped out w/ a profit.

        https://www.screencast.com/t/bVHKCyOb

        If anyone would like to look to see why the stop keeps moving back, here is my strategy.
        Attached Files
        Last edited by trdninstyle; 12-15-2022, 12:26 PM.

        Comment


          #5
          Hello trdninstyle,

          If you are trying to do what the example shows you need all of what is in that sample. Thats a complete sample that shows how to trail and hold the order open while unfilled. All of what that sample shows is the absolute minimum to do that trailing action, if you modify any of the sets then it won't work correct like the sample is intended to show.

          The reason I came back to just that trailing stop example was because the stop kept moving away from price on me & back down into negative territory instead of just being stopped out with a small profit or small loss.
          If the stop is moving in ways that are incorrect that would mean you modified part of the existing logic in an incorrect way. You can use the original sample as is to get trailing at a set freqecy, the stop won't move away from the price or back down it would only move when profit happens at a certain frequency.


          I assumed I got too complicated with my 22-set strategy & noticed that the example one that I had was doing the same thing, so I re-downloaded it & the stop worked properly. So, I wanted to keep that simple trailing behind price idea & add a set of conditions.
          I believe it would be best to go back to the basics here and make sure you fully understand what that trailing sample is doing before moving forward. The key take away is that your last set uses variables to keep the order active while unfilled. This is required because of the custom calculated price that is being used. The otherr sets also use varaibles to dictate when to change the stop price and what frequency that stop is modified.

          I would suggest to go through each set of the sample and make sure you completely understand why that code is used. Rather than trying to use the sample as is it would be best to use it to understand the concepts its relaying. You can keep other types of orders open using similar logic as long as you understand the concept of using variables and the sets logically to hold the order open. You can create any number of sets or variables you need to accomplish that task however without understanding the fundamental of what that sample shows it would be hard to add anything additional without breaking how the sample works.

          To use a limit order do I need to implement 5 sets? Also, I need to add a StopPrice variable.
          ​You would need to implement new variables and sets to use a limit order. If you review the trail sample you can see how an order is held open until filled by using a variable, you would need to do a similar task to make sure the condition for the order is true while the order is unfilled. None of the existing variables or sets would be used for that entry, you would be adding completely new variables and sets for your new type of entry order. The sample is intended to use a market order and relies on that to work.



          JesseNinjaTrader Customer Service

          Comment


            #6
            you need all of what is in that sample.
            So, I keep everything as it is, even the State=State.Realtime. But place my condition under that? Just for simplicity, Close(0) > Open(0)
            But isn't the example set up to trigger an entry at every moment? I also would want historical so I can pan back.


            The sample is intended to use a market order and relies on that to work.
            For now, I'll stay with a market order to keep it simple.

            Thank you for your explanations.
            Last edited by trdninstyle; 12-15-2022, 06:16 PM.

            Comment


              #7
              Hello trdninstyle,

              To have that sample work you would make 0 changes to it, its a complete sample that shows a few different concepts. Its really just intended to show how to dynamically price an order. Using that as a learning tool was the intention and not a starting point. If you want to do a similar task in your own script you can learn from that sample on how to do those type of actions and hold orders open. It was not intended to just use as is or so you can start modifying it, it will break if you make changes that conflict with the existing conditions and actions.

              JesseNinjaTrader Customer Service

              Comment


                #8
                The pivotal item here to adjust would have to be under the Misc to Misc? Like instead of Current State Equals State is Real Time rather make it Current State Equals Current Bar since I want a bull bar to be the current state to trigger.

                So, keep the original format but change the various items like that? Or Current Bar = Current State ?

                trdninstyle Click image for larger version

Name:	2022-12-16 10_15_51-2022_12_16_10_15_12_Strategy_Builder - Paint.png
Views:	215
Size:	24.6 KB
ID:	1227835

                Comment


                  #9
                  Hello trdninstyle,

                  I am not sure what you are asking to adjust. The state is where in processing the script is, its either processing in historical or realtime. The CurrentBar is an index of a bar that is being processed, you can't compare the State against the CurrentBar that's not a valid comparison.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    I did current bar = current bar. It looks good in historical view as entry being after a bull, but I just saw in real time that it entered right after a bear bar.

                    you can't compare the State against the CurrentBar that's not a valid comparison.
                    I did notice that.

                    What I'm asking here is obviously I can't just copy everything in this example tool, or I'll have the same thing. I need to use it as a tool so therefore mimic the steps in the example but change the things that matter until it works. It won't allow me to do something it doesnt allow.





                    Click image for larger version  Name:	2022-12-16 10_38_05-2022_12_16_10_37_41_Strategy_Builder - Paint.png Views:	0 Size:	21.6 KB ID:	1227840
                    Last edited by trdninstyle; 12-16-2022, 09:49 AM.

                    Comment


                      #11
                      Hello trdninstyle,

                      Again I am not sure what you are trying to achieve, that is also not valid. You are comparing the same number against the same number, that's just going to always be true.

                      You can use the help guide to get descriptions of the items you see in the builder, here is CurrentBar: https://ninjatrader.com/support/help...sub=currentbar

                      Current bar represents the bar being processed. You start processing bars in historical which starts at bar 0 or the left most bar. Each bar is processed and as it processes the CurrentBar index increases.

                      If we assume you are processing the first bar or bar 0 then the condition you pictured is saying if 0 equals 0. On bar 1 it would be saying if 1 equals 1.

                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Again I am not sure what you are trying to achieve,
                        To enter long once there is a bull bar.

                        Okay, do I keep those 4 sets exactly as they are, exactly. But add one more set to tell it my condition? Keeping the 4th set always last.

                        If I'm going to add a buy condition, I need to add two variables, right? Trigger State and Trigger Price
                        Last edited by trdninstyle; 12-16-2022, 10:32 AM.

                        Comment


                          #13
                          Hello trdninstyle,

                          Okay, do I keep those 4 sets exactly as they are, exactly. But add one more set to tell it my condition? Keeping the 4th set always last.


                          To learn from that sample you would change nothing, its showing very specific concepts. Its not made to change anything to become a normal strategy to use. It uses a generic entry condition that always happens because the entry condition is not the main point of that sample. The main point of that sample is the trailing action happening with the stop and also how to dynamically calculate a price for that stop. It also shows how to order the sets so you can make your own variables that control which sets are active. These are core concepts you need to learn if you want to do that type of action.

                          If you are planning to just modify that sample to use for trading I would suggest to avoid that and instead learn what each set in that sample is doing so you can do similar concepts in your own script that you created yourself.


                          To enter long once there is a bull bar.


                          To find a bull bar you would need to make a price condition, what constitutes a bull bar to you?

                          https://www.investopedia.com/terms/b...ys,two%20decli nes%20of%2020%25%20each.

                          If you use the public trading information page investopedia it lists a bull market as a period of time in financial markets when the price of an asset or security rises continuously. Is a bull bar in your mind a bar that has a close higher than the Open? If so you need to check if the Close is greater than the Open to know that.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            No, I don't know what a bull bar is, no clue.

                            Okay, thanks for your time.

                            Comment


                              #15
                              Hello trdninstyle,

                              If you are not sure what a bull bar is I would suggest researching that first so you know what general concept you need to use. When dealing with bars you will need to use prices so using the OHLC data would be needed. I would suggest reviewing the investopedia website if you are wanting to learn about different trading concepts, NinjaTrader does not document basic trading concepts we only document the NinjaScript API or how to control the platform with code. Once you know what trading concept you wanted to use you can execute that by making conditions that correlate with what you are trying to do.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ccrone2024, Today, 05:13 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post ccrone2024  
                              Started by ttodua, Today, 03:40 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post ttodua
                              by ttodua
                               
                              Started by ttodua, Today, 03:18 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post ttodua
                              by ttodua
                               
                              Started by TraderKnG, Today, 01:30 AM
                              0 responses
                              11 views
                              0 likes
                              Last Post TraderKnG  
                              Started by morrnel, 05-12-2024, 06:07 PM
                              8 responses
                              156 views
                              1 like
                              Last Post nobchi
                              by nobchi
                               
                              Working...
                              X