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

Strategy Builder and price crossing indicators

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

    Strategy Builder and price crossing indicators

    Here's my basic strategy I'm trying to setup with the Strategy Builder but can't seem to get it to work. I'd like to take a trade after the price crosses above a certain indicator (like an EMA, pivot point, etc.) within the last set number of bars (for example last 10 bars). Then when the price comes back to that indicator within the set number of bars, it enters the trade. Ideally with a limit order at the level of the indicator. I think the trouble I'm having is when the price crosses the indicator. Not quite sure how to do that. I've only ever done it to show indicators crossing each other. What is the easiest way to setup something like this?

    Thanks!

    #2
    Hello srtrader,

    Thank you for your post.

    You would basically need to do this in steps, and use a custom series to keep track of the bar on which the initial cross occurs. You can use CrossAbove/CrossBelow to find out if the strategy has crossed over an indicator plot. When you see the crossover, save the current bar number to the custom series, and set a bool to true. You can then check whether that bool is true, whether or not the Current Bar number is less than the value we've saved to the custom series + the number of bars within which to allow entry, and if the current price has crossed back over the indicator plot. If so, submit an order.

    I'm attaching a relatively simple example strategy that illustrates.

    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick response! I downloaded the sample strategy and still can't wrap my head around this. I've used the strategy builder quite a bit, but this all seems to be way over my head and I'm not even sure where to start. Are there any training videos that dive deeper into these concepts you are using? Like the bools and custom series.

      Thanks!

      Comment


        #4
        Hello srtrader,

        Thank you for your reply.

        I'd suggest starting with our Strategy Builder 301 video from our publicly available YouTube channel, as it touches on those concepts:

        Strategy Builder 301

        If you are new to C#, to get a basic foundation for the concepts and syntax used in NinjaScript I would recommend this section of articles in our NT7 help guide first:

        Basic Programming Concepts

        For general C# education I have personally found Dot Net Perls to be a great reference site with easy to understand examples.

        Browse examples for many languages, with explanations and code side by side for easy understanding.


        We also have some Reference samples online as well as ‘Tips and Tricks’ for both indicators and strategies:

        Click here to see our NinjaScript Reference Samples

        Click here to see our NinjaScript Tips

        These samples can be downloaded, installed and modified from NinjaTrader and hopefully serve as a good base for your custom works.

        Further, the following link is to our help guide with an alphabetical reference list to all supported methods, properties, and objects that are used in NinjaScript.

        Alphabetical Reference

        And our Educational Resources in the NinjaTrader 8 help guide.

        Educational Resources

        A set of specific tutorials for creating conditions in the NinjaTrader 8 Strategy Builder in the NinjaTrader 8 help guide.

        Condition Builder

        You can also contact one of our professional NinjaScript Consultants or Educators who would be eager to create or modify this script at your request or assist you with your script. Please let me know if you would like a list of professional NinjaScript Consultants or Educators who would be happy to create or modify any script at your request or assist you in learning NinjaScript.

        Please let me know if I may be of further assistance.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          So I went through the sample strategy you sent and got it to work exactly as planned. Thanks so much! My next question is how to setup this same type of thing but instead of crossing an indicator, it crosses a bar. For example, if I have a signal bar that meets certain criteria, it gets marked. And then for a long trade, when prices break above this signal bar, I enter long. I've tried to use the same criteria as the example strategy you sent that works with the indicator, but I can't seem to get it to work with a single signal bar. Does it need to be structured differently?

          Comment


            #6
            Hello srtrader,

            Thank you for your reply.

            You'd need to save the high of the signal bar to a variable so it can be referred back to. From there, you can compare the current price against the signal bar's saved high value and if the price exceeds that, then do something, like entering long.

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              I tried to set this up with a variable. It doesn't seem to be working though. Not sure I did it correctly. I've attached screenshots of how I set it up. FYI, this is for taking shorts below the low of a previous marked bar.
              Attached Files

              Comment


                #8
                Hello srtrader,

                Thank you for your reply.

                I'm not seeing anything amiss in your screenshots. Could you supply the strategy so I may test on my end? You can export it from Tools > Export > NInjaScript Add-on. Do not check the box to export as a compiled assembly or I will not be able to review your logic. Please attach the resulting .Zip file to your reply.

                Thanks in advance; I look forward to assisting you further.
                Kate W.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by actualfacts.2021, 07-25-2021, 03:11 PM
                9 responses
                1,194 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by NinjaTrader_ChelseaB, 03-14-2017, 10:17 AM
                228 responses
                34,324 views
                7 likes
                Last Post NinjaTrader_ChelseaB  
                Started by Philippe56140, 04-27-2024, 02:35 PM
                8 responses
                66 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by memonic, Yesterday, 01:23 PM
                3 responses
                26 views
                0 likes
                Last Post memonic
                by memonic
                 
                Started by Luke Heinrich, Yesterday, 03:25 PM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X