• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Possible to say enter trade X bars after indicator does Y

  • Filter
  • Time
  • Show
Clear All
new posts

    Possible to say enter trade X bars after indicator does Y

    Looking to say enter trade X bars after MACD cross unless MACD crosses back within that 8 bar period. Is this possible using the Strategy Builder?

    Hello demo166130,

    Thanks for your post.

    This could be possible by setting a few bools for 1) when you are waiting for the number of bars to be met, and 2) for each bar that you have waited.

    When your waiting bool is true and the last bool that you set for X bars is true, then you can call your Enter method.

    If a cross in the other direction occurs, set these bools back to false.

    An example for using bools to count would be as follows:

    if(NeedToCount == true && BoolCounted2 == true)
        BoolCounted3 = true;
    if(NeedToCount == true && BoolCounted1 == true)
        BoolCounted2 = true;
    Please let me know if I can be of further assistance.
    JimNinjaTrader Customer Service


      Im catching your drift but it goes over my head when you start mentioning C#. Which input parameters would I use within the strategy builder to say what your code says?


        Hello demo166130,

        I have created a demonstration showing how bools can be set up in the Strategy Builder to count how many bars ago something had happened.

        Demo - https://drive.google.com/file/d/1pPx...w?usp=drivesdk

        Please let me know if I can be of further assistance.
        JimNinjaTrader Customer Service


          I really appreciate you taking the time to try and explain this to me. Think it'll require a few more watches before what's going on actually sinks in.

          Got a couple questions, what derives the meaning given to terms like 'BoolWaited1Bar', is this preset within the programme language?
          Just to confirm this would set an entry to take place 3 bars after the SMA cross takes place, providing the SMA doesn't cross back again?
          If I wanted to use the same logic, only when the Fast SMA crosses Below the SlowSMA go Short instead of long, would this have to be written out again using another 6 sets? (This might be a dumb question).




            Hello Alex,

            The variable names are names I chose to give them meaning.

            Yes, this will enter long 3 bars after the cross from Set 5 is seen. If the other cross is seen (Set 6) the variables are reset and counting stops.

            You should use separate variables and use separate logic to handle another type of cross, but if you wanted to use a different cross than what I defined, you could change Set 5.

            My best recommendation for learning NinjaScript is to set up test logic in small cases and to use the Playback Connection and the Simulated Data Feed to control your tests. Once you confirm some set of logic works, I would then recommend expanding on it.

            Let us know if you have any additional questions.
            JimNinjaTrader Customer Service


              Thanks for clearing that up. So how do the variables have any effect on the strategy if you derive their meaning yourself? As in how will the system know you are telling it to take a trade 8 bars after the indicator provides the signal if names like BoolWaited3Bars don't actually have any meaning?

              You mentioned using seperate variables to create a series in which we wait X bars to take a trade the other direction. So a variable like BoolWaited3BarsShort would be fine?

              A part of the strategy I was also hoping to create is to exit trade after 8 bars. Is this more simple to integrate?


                Hello demo166130,

                Perhaps I could have explained better: the logic in which the the bools are used defines the meaning for the strategy. The name chosen is to provide an visual aid so as the strategy developer, I know what I want that bool to represent and how I should use it.

                You mentioned using separate variables to create a series in which we wait X bars to take a trade the other direction. So a variable like BoolWaited3BarsShort would be fine?
                You would have to recreate the logic as it is modeled and add more variables/conditions to check for 4 bars, 5 bars, 6 bars, or as many as needed.

                There is not an easier way to count within the Strategy Builder, but may be easier to program by hand in an unlocked strategy.

                If creating the logic is difficult and you are interested in services to have the logic or Strategy code written for you, we could have a representative of our EcoSystem reach out with information on NinjaScript consultants who would be happy to write a custom strategy by your request.

                Please let us know if we can be of further assistance.
                JimNinjaTrader Customer Service


                  It would be great if you could have an EcoSystem representative make contact to discuss things. There are a number of indicators it would be interesting to know if were possible to be made to work in conjunction with a mchanical strategy. Look forward to hearing from someone in due course.



                    Hello demo166130,

                    Thank you for your reply.

                    You can search our extensive library of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more:You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third-party services for NinjaTrader, all pricing and support information will need to be obtained through the consultant.

                    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem, LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

                    Let me know if I may be of further assistance.
                    Christopher D.NinjaTrader Customer Service


                    Latest Posts


                    Topics Statistics Last Post
                    Started by johnnybegoode, Today, 07:15 PM
                    0 responses
                    Last Post johnnybegoode  
                    Started by rtwave, Today, 06:55 PM
                    0 responses
                    Last Post rtwave
                    by rtwave
                    Started by Apeppo, Today, 02:53 PM
                    0 responses
                    Last Post Apeppo
                    by Apeppo
                    Started by johng964, Today, 01:33 PM
                    2 responses
                    Last Post johng964  
                    Started by U0000999, Today, 12:07 PM
                    3 responses
                    Last Post NinjaTrader_ChrisL