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

Price Data on Chart Indicator

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

    Price Data on Chart Indicator

    Hey guys I'm trying to make a simple Indicator, that draws a couple of horizontal Lines 10 ticks above the Close and 10 ticks below the close. But on those lines I want what ever the Price Level is to be drawn in big Bold Letters automatically.

    Any idea how to code this. Help please with example codes.

    So far this is all I have:
    if (Close[0] > Open[0])
    {
    DrawHorizontalLine("My horizontal line" + CurrentBar, High[0] + 10 * TickSize, Color.DarkSlateGray);
    DrawText("My text" + CurrentBar, "", 0, High[0] + 10 * TickSize, Color.Red);
    }

    //Trying to Draw the price level 10 ticks above the High of the current bar.
    It's Not working.
    Last edited by ginx10k; 05-08-2014, 03:54 PM. Reason: added Code snippet

    #2
    Hi ginx10k,

    The code you are using looks OK.

    I tested this with

    DrawHorizontalLine("My horizontal line", High[0] + 10 * TickSize, Color.DarkSlateGray);
    DrawText("My text" + CurrentBar, "", 0, High[0] + 10 * TickSize, Color.Red);

    So that only the line on the last bar is drawn. This worked correctly.

    The DrawText is not drawing anything because the text string is an empty string.

    What is the incorrect behavior you are experiencing?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      The Price Level is NOT being drawn on the chart. I don't know how to use the Draw text so that it can draw Price level. for instance, If the current High is 1.2010 and I wanna draw a line at 1.2020 but I also want the Price ("1.2020") to be drawn on top of the Line.

      I don't know how to do this. please help.

      Comment


        #4
        Hello ginx10k,

        Thank you for your response.

        We would need to store the value of High[0] + 10*TickSize and then print that value:
        Code:
        double highPlusTen = High[0] + 10 * TickSize;
        DrawText("My text" + CurrentBar, highPlusTen.ToString(), 0, High[0] + 10 * TickSize, Color.Red);

        Comment


          #5
          Wow. got it to work. Thanks a lot Guys.

          Comment


            #6
            One more problem!

            I'm trying to customize the size of the Horizontal Line. and I read somewhere that I Can't change size of the "DrawObjects". that I have to make my own.

            But when I try this code it keeps showing compiling error. Something about Overloading method, that I can't turn int to Double. Can you help me out please.

            Code:
             protected override void Initialize()
                    {
                       //Set the First Horizontal Line Plot
            			Add(new Plot(Color.FromKnownColor(KnownColor.Purple), PlotStyle.HLine, "Plot0"));
            			
            			//Increase Line's default widths
            			Plots[0].Pen.Width = 4;
            			
            			CalculateOnBarClose = false;
                        Overlay				= false;
                    }
            
                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
                        // Use this method for calculating your indicator values. Assign a value to each
                        // plot below by replacing 'Close[0]' with your own formula.
                        // Condition set 1
                        if (Close[0] > Open[0])
                        {
                            Plot0.Set(High[0] + 10 * TickSize, Color.DarkSlateGray);
                            DrawText("My text", highPlusTen.ToString(), 0, High[0] + 11 * TickSize, Color.Red);
                        }
                    }

            Comment


              #7
              ginx10k,

              Which line is the compile error coming from?

              The DrawTex()t looks fine for overloads
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Im trying to customize my own Horizontal Lines. Widths. but don't know how to do it. I tried to plot but it doesn't work.

                Here are the Full Errors: http://screencast.com/t/RJ2cdkFmclUi


                Can you help me customize my own Horizontal Lines, and plot them. Thanks

                Comment


                  #9
                  Ginx10k,

                  The plot setting that you are doing is no the correct overload for .Set()
                  It takes an int as the first Argument and a double for the second.

                  Additionally, you would want to set the color and width like you did with Plots[0] in the initialize here as well.
                  Code:
                  Plot0.Set(High[0] + 10 * TickSize);
                  Plots[0].Pen.Color = Color.DarkSlateGray;
                  Plots[0].Pen.Width = 3;
                  You can also use the overload method of DrawHorizontalLine() with the width property -
                  Code:
                  DrawHorizontalLine(string tag, bool autoScale, double y, Color color, DashStyle dashStyle, int width);
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    I tried the DrawHorizontalLine Overload,




                    I don't know what I'm putting in Wrong. keep getting errors.

                    Code:
                     DrawHorizontalLine("My horizontal line", High[0] + 10 * TickSize, Color.DarkSlateGray, DashStyle.Dash, 3);
                                    DrawText("My text", highPlusTen.ToString(), 0, High[0] + 11 * TickSize, Color.Red);

                    Comment


                      #11
                      Ginx10k,

                      You're missing the autoscale bool property in that as well
                      Code:
                      DrawHorizontalLine("My horizontal line", [B]true[/B],High[0] + 10 * TickSize, Color.DarkSlateGray, DashStyle.Dash, 3);
                      Cal H.NinjaTrader Customer Service

                      Comment


                        #12
                        Yessss!!!

                        Got It. thank you so much Buddy. Awesome!!

                        Comment


                          #13
                          Text Font Size

                          A couple more questions:

                          1. I can't get the Fonts to change size in the DrawText()

                          I tried
                          Code:
                           DrawText("My text", true, highPlusTen.ToString(), 0, High[0] + 12 * TickSize, Font Arial 10px, Color.Red);
                          Keep getting compile error: ") expected" and "; expected"

                          2. and How do I add Text before the highPlusTen.ToString(), so that when it Prints on chart it can say "BUY: highPlusTen.ToString(),". I tried to just type in that line but get compiling errors.

                          any idea how to get this done properly.
                          Last edited by ginx10k; 05-09-2014, 09:25 AM.

                          Comment


                            #14
                            Ginx10k,

                            You need to make sure that you are following the correct overload methods that are available for the DrawObjects. You can check the Draw methods from the link below and what the overloads are -
                            http://www.ninjatrader.com/support/h...ml?drawing.htm

                            Additionally, if you are going to change the font inline like that you need to create a new font as such
                            Code:
                            new Font("Arial", 10)
                            Also, add "Buy: " + before the highPlusTen string
                            Cal H.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello Ginx10k,

                              To add more to the string you already have you would just need to use an + sign in-between the two strings and format it how you would like it.

                              Here is an example using what you had posted with the Buy: added in:

                              Code:
                              DrawText("My text", true, "Buy: " + highPlusTen.ToString(), 0, High[0] + 12 * TickSize, Color.Red);
                              Please let me know if I may be of further assistance.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by wzgy0920, 04-20-2024, 06:09 PM
                              2 responses
                              26 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, 02-22-2024, 01:11 AM
                              5 responses
                              32 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, Yesterday, 09:53 PM
                              2 responses
                              49 views
                              0 likes
                              Last Post wzgy0920  
                              Started by Kensonprib, 04-28-2021, 10:11 AM
                              5 responses
                              192 views
                              0 likes
                              Last Post Hasadafa  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              11 responses
                              3,234 views
                              0 likes
                              Last Post xiinteractive  
                              Working...
                              X