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

Draw arrow on existing indicator

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

    Draw arrow on existing indicator

    Hey fellas -

    This is a beginner type question...

    I want to modify an existing indicator like the Stochastic to draw an Arrow Up/Down on the price chart whenever there's a crossover.
    Is there an easy way to do this?

    Thanks!

    #2
    Hello PN720,

    Thanks for your post.

    Easy is quite relative. If you have experience with C# and or Ninjascript it is not difficult, otherwise, it can be quite difficult, the first time.

    To draw the arrow you would need to detect a crossover, in Ninjascript you can use the CrossAbove() and CrossBelow() methods:



    To Draw an arrow, you would use Draw.ArrowUp() and likely Draw.ArrowDown() methods:



    An alternative, that may be easier, is to use the strategy builder to create the condition of the crossabove/below and the action to draw the arrow up/down. Once you have done that then you can use the "view code" of the strategy builder to see how to create the correct code.

    For educational purposes, I have attached a modified stochastics indicator that will draw an up arrow when the K line crosses above the D line. You are welcome use, study and modify as you wish. The arrows will be drawn a few ticks below the low of the bar where the cross occurred.

    If you would like to take on learning NinjaScript, we have a fully documented help guide which will help you get started.

    In the help guide there are language references to all of the methods and functions you will be using.
    All links below are publicly available.
    First up is a link to a set of specific tutorials for creating conditions in the NinjaTrader 8 Strategy Builder in the NinjaTrader 8 help guide: https://ninjatrader.com/support/help...gy_builder.htm

    The entire Alphabetical Reference can be found with the following link: https://ninjatrader.com/support/help..._reference.htm

    Below are links to Reference Samples online as well as some Tips and Tricks for both indicators and strategies. These samples can be downloaded, installed and modified from NinjaTrader and hopefully serve as a good base for your custom works.

    Click here to see our NinjaScript Reference Samples:


    Click here to see our NinjaScript Tips: https://ninjatrader.com/support/help...n-us/?tips.htm

    The best way to begin learning NinjaScript is to use the Strategy Builder. With the Strategy Builder you can setup conditions and variables and then see the generated code in the NinjaScript Editor by clicking the View Code button.

    I'm also proving a link to a pre-recorded set of videos 'Strategy Builder 301' and 'NinjaScript Editor 401' for you to view at your own convenience.
    Strategy Builder 301 - https://www.youtube.com/watch?v=HCyt...ZmVnauWXkWe0Nf
    NinjaScript Editor 401 - https://www.youtube.com/watch?v=BA0W...ZmVnauWXkWe0Nf

    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:



    Here is a link to the Educational Resources section of the Help Guide to help you get started with NinjaScript: https://ninjatrader.com/support/help..._resources.htm

    There is also a growing library of user-submitted custom indicators (100+) that can be downloaded from our support form. Please look in the NinjaScript File Sharing section of our support forum as you may find what you are looking for there: https://ninjatrader.com/support/foru...ks.php?catid=7

    Last, I'm also sharing a link to another forum post that reviews how to use prints to understand behavior and debug a script when the behavior is unexpected. https://ninjatrader.com/support/foru...979#post510979
    Attached Files
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,
      Thank you for the prompt response and that sample code as it's exactly what I needed.
      One follow-up question is if I wanted plot the arrows on the indicator instead of the price panel. I see that the DrawArrowUp command has a DrawOnPricePanel bool at the end. When I switch it to false, the arrows draw on the Indicator panel but they're all scrunched at the top and the Plot lines are gone. Is there something else I need to set?

      Comment


        #4
        Hello PN720,

        Thanks for your reply.

        You would need to specify the vertical (Y) location for the arrows. As provided it was set to the Low price - 3 *TickSize. The stochastic indicator panel will range from 0 to 100, so you might replace Low[0] - 3 * TickSize with K[0] or D[0] which would be the current value of the K line or D line. You may have to experiment with different values to subract if you want to move the arrows away from the cross. You would not need to specify TickSize because your arrows are not in the price panel, so something like K[0] - 3may be an example that might work.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          PaulH,

          This is exactly what I was looking for as well but when I download the file it says it is corrupt. Is it possible to re-upload? Let me know, thanks!

          Comment


            #6
            Hello teekay,

            Thanks for your post.

            I just tested the download and was able to download and install without any errors. You may want to try a different browser.

            Here are our basic ninjascript installation directions:

            To import NinjaScripts you will need the original .zip file.

            To Import
            1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
            2. From the Control Center window select the menu Tools>Import>Ninjascript add-on
            3. Select the downloaded .zip file
            4. NinjaTrader will then confirm if the import has been successful.

            Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

            Once installed, you may add the indicator to a chart by:
            • Right click your chart > indicators > Select the Indicator from the list on the left > New > OK
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Paul,

              I have NT7, does that have anything to do with this?

              Comment


                #8
                Hello teekay,

                Thanks for your reply.

                Ninjascript is not compatible between NinjaTrader8 and NinjaTrader7 so yes that would be the issue for you.

                You can download NT8 from here: https://ninjatrader.com/PlatformDirect
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Paul, is there anything like it available for NT7?

                  Comment


                    #10
                    Hello teekay,

                    Thanks for your reply.

                    The intent of the thread and my post #2 was to provide direction towards learning how to modify an indicator to add arrows. In the example code I provided, this is the code that I actually added (for NT8):

                    Code:
                                 if (CrossAbove(K, D, 1))
                                {
                                    Draw.ArrowUp(this, "tagA"+CurrentBar, true, 0, Low[0] - 3 * TickSize, Brushes.CornflowerBlue);
                                }
                    The code above only draws up arrows so it is not a complete indicator that shows up and down arrows and again the intent was to provide an educational example/starting point.


                    For NT7, here would be the exact same functional code but for NT7 which has a slightly different syntax:
                    NT7***** ONLY******
                    Code:
                                if (CrossAbove(K, D, 1))
                                {
                                    DrawArrowUp("tagA"+CurrentBar, 0, Low[0] - 3 * TickSize, Color.CornflowerBlue);
                                }

                    The above code would be placed just below the last line of code in a copy of the stochastics indicator, in NT7 the last line looks like: D.Set(SMA(K, PeriodD)[0]);

                    You can also do the same thing by using the strategy wizard, here is a link to the strategy wizard video on using the wizard to create alerts (and in this case arrows): https://www.youtube.com/watch?v=vt0s...A140D7&index=6 the NT7 strategy wizard will create the code for you.

                    If you have further questions or need further assistance, please create a new thread in the NT7 forum so we do not provide further confusion for those that come after looking for NT8 help in this thread. Thanks in advance for your understanding.
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello,

                      I have been using the ECO2NEW2 indicator. The indicator has arrows that print on the same panel as the indicator. How would I program the indicator to print the arrows on my chart?

                      Comment


                        #12
                        Hello tbergmann9919,

                        Are the arrows drawn with Draw.ArrowUp() / Draw.ArrowDown()?
                        Or are they custom rendered in OnRender()?

                        If these are drawing objects with Draw methods, set DrawOnPricePanel to true in State.Configure.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea,

                          Thank you for the response. When I set the Drawonprice panel to True The arrows print on the chart. They print on the 0 line. So, the arrows are all in a row at the bottom of the chart, and the chart is tiny at the top of the chart. What would I have to do to get the arrows to print above the chart for down and below the chart for up. Preferably by a couple of ticks?

                          Comment


                            #14
                            Hello tbergmann9919,

                            Supply the price you want the object drawn at to the draw method.

                            Try supplying a price of High[0] + 3 * TickSize to draw above the bar.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Thank you, Chelsea. I am definitely not good with code. Where in the code do I change the draw method?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by judysamnt7, 03-13-2023, 09:11 AM
                              4 responses
                              59 views
                              0 likes
                              Last Post DynamicTest  
                              Started by ScottWalsh, Today, 06:52 PM
                              4 responses
                              36 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by olisav57, Today, 07:39 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post olisav57  
                              Started by trilliantrader, Today, 03:01 PM
                              2 responses
                              21 views
                              0 likes
                              Last Post helpwanted  
                              Started by cre8able, Today, 07:24 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post cre8able  
                              Working...
                              X