• 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.

Announcement

Collapse
No announcement yet.

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:
        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 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

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Sh00tHerMcGavin, Today, 07:39 PM
              0 responses
              1 view
              0 likes
              Last Post Sh00tHerMcGavin  
              Started by Mberg, Today, 05:13 PM
              0 responses
              0 views
              0 likes
              Last Post Mberg
              by Mberg
               
              Started by Barry Milan, Today, 01:33 PM
              2 responses
              8 views
              0 likes
              Last Post marcus2300  
              Started by NW Trader, Today, 03:42 PM
              2 responses
              7 views
              0 likes
              Last Post NW Trader  
              Started by ralett, Today, 01:42 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Working...
              X