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

Looking to build simple indicator -- need help

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

    Looking to build simple indicator -- need help

    Hello,

    I am looking to build a simple indicator, the code for which I am hoping will also be simple. All I want is for the indicator to plot horizontal lines at two multiples of ten above and below current price. So for example if the exact price was 7182.25, I want the indicator to plot horizontal lines at 7190.00 and 7180.00. Or if it would be easier to do, simply plot multiples of 10 within a given range, i.e. from 7100.00 to 7200.00, what do you think?

    P.S. I know that I can set up grid lines to represent exactly what I am talking about, however unless anybody knows a way to call upon grid lines in a strategy, that information isn't useful for me.

    Thank you for any help you can offer, I look forward to your guidance.

    #2
    Hello lunardiplomacy,

    Thanks for your post.

    If I understand correctly you want to draw 20 horizontal lines, every time the price changes.

    To draw a horizontal line you would use the method Draw.HorizontalLine(): https://ninjatrader.com/support/help...zontalline.htm

    You would need to use 20 different tag names so that as your code draws a new line it will delete the previously (no longer relevant) line.

    You would need to decide how often you update the lines, if you truly want them to shift on every price change, then you would want to use the calculate mode of Calculate.OnPriceChange. Reference: https://ninjatrader.com/support/help...?calculate.htm

    If you only want to update periodically, then you would need to decide how frequently to update and what price type to use for the reference.

    If you always want to see all 20 lines regardless of price, then you would need to set your autoscale to true to include the horizontal lines in the charts autoscaling.


    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello lunardiplomacy,

      Thanks for your post.

      If I understand correctly you want to draw 20 horizontal lines, every time the price changes.

      To draw a horizontal line you would use the method Draw.HorizontalLine(): https://ninjatrader.com/support/help...zontalline.htm

      You would need to use 20 different tag names so that as your code draws a new line it will delete the previously (no longer relevant) line.

      You would need to decide how often you update the lines, if you truly want them to shift on every price change, then you would want to use the calculate mode of Calculate.OnPriceChange. Reference: https://ninjatrader.com/support/help...?calculate.htm

      If you only want to update periodically, then you would need to decide how frequently to update and what price type to use for the reference.

      If you always want to see all 20 lines regardless of price, then you would need to set your autoscale to true to include the horizontal lines in the charts autoscaling.

      Hi Paul, thank you for your reply,

      Yes, I think it's best to go with a range rather than use two horizontal lines at intervals of 10 above and below current price.

      So, I think you are understanding... basically I would want 20 horizontal lines to be plotted at intervals of 10 within a price range of $200. So for NQ E-mini for example, I would want 20 horizontal lines, starting at 8300 and going up by $10 each time until 8500.

      And, yes I would want to scale to price only so I don't have squished price action all the time, but I know how to do that already, good point though.

      Would it be too much to ask of you to give a code snippet for what just one horizontal line would look like within that range? I don't understand how to connect plots/lines with logic/values.

      Thank you, Paul.

      Comment


        #4
        Hello lunardiplomacy,

        Thanks for your reply.

        Here is an example as requested:

        Code:
        [I]protected override void OnBarUpdate()
                {
                    if (CurrentBar == 0)  // Drawing it once on the first bar of data loaded
                    {
                        for (int i = 0; i <= 20; i++)
                        {
                            Draw.HorizontalLine(this, ("HLineAT"+(StartPrice+i*10)), StartPrice+i*10, Brushes.Blue);
        
                        }
                    }
                }[/I]
        I created a double type input called StartPrice that was used as the starting price.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          I think what you want is the Magic Numbers indicator. Or something along that line. Feel free to edit it.
          Have a look at this.
          Attached Files

          Comment


            #6
            Originally posted by Gorkhaan View Post
            I think what you want is the Magic Numbers indicator. Or something along that line. Feel free to edit it.
            Have a look at this.
            Ahhh, so there you have it. Thank you very much for that. At least now I know how to do it myself if need be, but this one you sent me is much more organized and put together, so I'm going to use it.

            Thank you, Gorkhaan

            Comment


              #7
              Originally posted by lunardiplomacy View Post

              Ahhh, so there you have it. Thank you very much for that. At least now I know how to do it myself if need be, but this one you sent me is much more organized and put together, so I'm going to use it.

              Thank you, Gorkhaan
              No worries. Enjoy. :-)

              Comment


                #8
                Originally posted by Gorkhaan View Post
                I think what you want is the Magic Numbers indicator. Or something along that line. Feel free to edit it.
                Have a look at this.

                is it only me or the indicator doesnt work anymore? doesnt plot any lines

                Comment


                  #9
                  Hello polo0202,

                  Thanks for your post.

                  I just downloaded and applied it to a chart, seems to work here (see attached). Do you see any error messages in the "log" tab of the control center related to the indicator?

                  Click image for larger version

Name:	polo0202-1.PNG
Views:	502
Size:	32.8 KB
ID:	1136328
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello polo0202,

                    Taking a closer look at the indicator, it appears that it is written for instruments with larger values. An instrument with a price value of less than 100 would not see many if any lines (unless you compress the price scale).

                    To see the lines on smaller priced instruments, you would need to rework the code provided by member Gorkhaan.

                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_PaulH View Post
                      Hello polo0202,

                      Taking a closer look at the indicator, it appears that it is written for instruments with larger values. An instrument with a price value of less than 100 would not see many if any lines (unless you compress the price scale).

                      To see the lines on smaller priced instruments, you would need to rework the code provided by member Gorkhaan.
                      Thanks Paul, thats why i cant see it on Forex. Is there any free round numbers indicator?

                      Comment


                        #12
                        Hello polo0202,

                        Thanks for your reply.

                        I am not aware of another indicator.

                        Have you looked at changing the charts' horizontal gridlines to meet your needs? This is an oft-overlooked capability that may be helpful to you.

                        In the price column of the chart, right mouse click and select "properties". Next change the "Horizontal gridlines from "automatic" to "fixed" Note that you can now adjust these lines on points, pips, or ticks basis and can specify the interval. Finally, on the chart itself, right mouse click and select "Properties" and in the chart properties you can adjust the visual characteristics of the gridlines.

                        I've attached two screenshots, the top one shows with the panel properties open, the 2nd with the chart properties open. Hopefully, this will help.

                        Click image for larger version

Name:	polo0202-2.PNG
Views:	532
Size:	238.5 KB
ID:	1136395

                        Click image for larger version

Name:	polo0202-3.PNG
Views:	507
Size:	72.9 KB
ID:	1136396
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_PaulH View Post
                          Hello polo0202,

                          Thanks for your reply.

                          I am not aware of another indicator.

                          Have you looked at changing the charts' horizontal gridlines to meet your needs? This is an oft-overlooked capability that may be helpful to you.

                          In the price column of the chart, right mouse click and select "properties". Next change the "Horizontal gridlines from "automatic" to "fixed" Note that you can now adjust these lines on points, pips, or ticks basis and can specify the interval. Finally, on the chart itself, right mouse click and select "Properties" and in the chart properties you can adjust the visual characteristics of the gridlines.

                          I've attached two screenshots, the top one shows with the panel properties open, the 2nd with the chart properties open. Hopefully, this will help.

                          Click image for larger version

Name:	polo0202-2.PNG
Views:	532
Size:	238.5 KB
ID:	1136395

                          Click image for larger version

Name:	polo0202-3.PNG
Views:	507
Size:	72.9 KB
ID:	1136396

                          thanks a lot for your help Paul, this surely helped me thanks again for your kindness

                          Comment


                            #14
                            Hi, guys , where can i dowload Magic Numbers indicator ?

                            Comment


                              #15
                              Hello hunterll,

                              Thanks for your notes.

                              You could download the MagicNumbers.zip file shared by Gorkhaan on post # 5.

                              After downloading the MagicNumbers.zip file, go to Control Center > Tools > Import > NinjaScript AddOn to import the NinjaScript onto your NinjaTrader 8 platform.

                              Or, you could browse the NinjaTrader Ecosystem User App Share linked below for a 'MagicNumbers' indicator or one that works similarly.

                              Ecosystem User App Share: https://ninjatraderecosystem.com/user-app-share/


                              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 add-ons 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.
                              Brandon H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by elirion, Today, 01:36 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Started by gentlebenthebear, Today, 01:30 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post gentlebenthebear  
                              Started by samish18, Yesterday, 08:31 AM
                              2 responses
                              9 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Started by Mestor, 03-10-2023, 01:50 AM
                              16 responses
                              389 views
                              0 likes
                              Last Post z.franck  
                              Started by rtwave, 04-12-2024, 09:30 AM
                              4 responses
                              33 views
                              0 likes
                              Last Post rtwave
                              by rtwave
                               
                              Working...
                              X