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


No announcement yet.

Partner 728x90


Draw vertical line to next Pivot

  • Filter
  • Time
  • Show
Clear All
new posts

    Draw vertical line to next Pivot

    This draws a vertical slightly slanted line from the Low of the Bar to the Close plus 10ticks.

    DrawLine("tag1" + CurrentBar, false, 1, Low[0], 0, Close[0] + 10 * TickSize, Color.Lime, DashStyle.Solid, 2);

    Is there a way to draw the line instead to the next Pivot? In other words, substitute the blue colored part with something telling it to search for the next available higher pivot?



    Thank you for the post.

    I wanted to check, are you asking about drawing a pivot you have calculated somewhere in the script already? Or are you referring to getting pivot information from the pivot indicator? Could you provide more detail on the pivot you are referring to?

    The area you have highlighted would need to be a price value, so if you have already calculated data somewhere in the script you would just need to reference that data in the blue area by means of a variable. Otherwise an indicators value or equation could be used.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service



      I meant to get the data from the standard NT Pivot indicator, whereby "it" should "look for" and determine what is the next available pivot. In this example going long, it should state based on where price is at whether that's R1, R2 or R3.



        Hello sandman,

        Thank you for your patience.

        The code would be as follows:
        DrawLine("tag1"+CurrentBar, false, 1, Low[0], 0, Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 3).R1[0], Color.Lime, DashStyle.Solid, 2);
        Patrick H.NinjaTrader Customer Service


          I would like to draw a vertical line on a range chart that extends to the entire height of the chart when a certain condition is met and also the width of the line should match the width of the range bar.

          What is the code to do this please?



            I tried something similar but could not get a DrawLine command to do what I wanted. I ended up using DrawRectangle instead.

            If (condition)

            {DrawRectangle("RectUp", false, 1, Open[0] - offset * TickSize, 0, Open[0] + offset * TickSize, Color.Transparent, upColor, opacity);

            "offset" is userdefinable and when I set it for example to "100" it draws the rectangle from top to bottom of the chart. (Depending on the instrument you may have to use "200").
            "upcolor" is user defined as is "opacity" as that allows me to fine tune how visible I want that line/stripe/rectangle to be in the chart.

            Note that this is only for a current bar. If past ones should also be visible you would need to change the tag to ("RectUp" + CurrentBar).



              Thanks Sandman. I used the code to display a rectangle on the Gomi order flow chart using range bars when two consecutive long signals are generated.


                Hello mballagan,

                Thanks for writing in.

                It sounds like sandman has been able to assist you with your inquiry.

                While DrawVerticalLine() provides easy implementation for a vertical line, its width cannot reach the same limits that you can with a DrawRectangle() call. Creating a vertical drawing object the same width as bar's bar width can be more appropriately done with DrawRectangle().

                For the thread's reference, I will provide a link below:


                Please let me know if I may be of further assistance with your inquiry.
                JimNinjaTrader Customer Service


                  Trying to understand NTs Pivots indicator

                  Hi there

                  I am trying to understand the Pivots indicator (see attachment). For each Pivot (PP, S1, R1 etc) it seems to write a title: the name of the pivot (PP etc) followed by a line. I'd like to move the title over to the right of the current bar but I can't for the life of me find the actual code that draws the line and the "PP". (I am a long time programmer but new to C#)

                  Can anyone help.


                  Attached Files


                    Hello daij1944,

                    Welcome to the forums!

                    The section of code that renders the lines and text are located in the OnPlot() override.

                    I have copied the relevant section of code:

                    using (GraphicsPath	path = new GraphicsPath()) 
                    					if (brush.Color != plot.Pen.Color)	
                    						brush = new SolidBrush(plot.Pen.Color);
                    					for (int idx = this.LastBarIndexPainted; idx >= Math.Max(this.FirstBarIndexPainted, this.LastBarIndexPainted - Width); idx--)
                    						if (idx - Displacement < 0 || idx - Displacement >= Bars.Count || (!ChartControl.ShowBarsRequired && idx - Displacement < BarsRequired))
                    						else if (!series.IsValidPlot(idx))
                    						if (idx < firstBarIdxToPaint)
                    						double	val = series.Get(idx);
                    						int		x	= ChartControl.GetXByBarIdx(BarsArray[0], idx);
                    						int		y	= ChartControl.GetYByValue(this, val);
                    						if (lastX >= 0)
                    							if (y != lastY) // Problem here is, that last bar of old day has date of new day
                    								y = lastY;
                    							path.AddLine(lastX - plot.Pen.Width / 2, lastY, x - plot.Pen.Width / 2, y);
                    						lastX	= x;
                    						lastY	= y;
                    					graphics.SmoothingMode = SmoothingMode.AntiAlias;
                    					graphics.DrawPath(plot.Pen, path);
                    					graphics.SmoothingMode = oldSmoothingMode;
                    					graphics.DrawString(plot.Name, ChartControl.Font, brush, lastX, lastY - textHeight / 2, stringFormatFar);
                    The line is drawn with path.AddLine() and the text is drawn with graphics.DrawString().

                    I would advise to clone the indicator and to modify the x and y coordinates until you have the plots where you want them.

                    Please let me know if I may be of further assistance.
                    JimNinjaTrader Customer Service


                      you are a gem. thank you. (i haven't quite got what i want yet, so i may be back with more questions


                        Adapting Pivot Indicator

                        hi jim

                        many thanx

                        i get it but i still got stuck

                        here's the problem

                        i substituted x+20 and x-10 for the second x coordinate (see screen prints) but i get almost the same line (x+20 goes all the way to the last bar, x-10 stops 2 bars before)

                        is this being overridden somewhere else?

                        am i missing something? i am quite lost

                        best wishes

                        Attached Files


                          Hello daij1944,

                          Thanks for the reply.

                          You are modifying pixel coordinates instead of referencing a bar when using path.AddLine(). 20 pixels is a lot less screen space than what 20 bars can take up.

                          The Plot() override is not something that we have documented, and as such, we would not be able to provide support for. There are certain ways you can reference the bar to get a coordinate point, but there are certain implications involved when you try to reference a bar from Plot(). You would have to use ChartControl to access pixel values of a bar, and you can use IsValidPlot() to make sure the bar you are referencing is valid before you do to avoid run time errors.

                          All of this is possible, but undocumented. At this point, if you want to delve more into unsupported rendering in NinjaTrader 7, I would recommend to view the Plot() code in some 3rd party indicators hosted here.

                          The Fibonacci Cluster indicator has some of these unsupported methods and properties used if you would like to look into using those to setting your line to be so many bars back. Otherwise, you could modify the line by its pixel coordinates alone.

                          Fibonacci Cluster - http://ninjatrader.com/support/forum...catid=4&id=344

                          Many undocumented items have been discussed here: http://ninjatrader.com/support/forum...ad.php?t=22435
                          JimNinjaTrader Customer Service


                            i get it

                            many thanx


                            Latest Posts


                            Topics Statistics Last Post
                            Started by Jonathan.Lee, Today, 11:29 AM
                            1 response
                            Last Post NinjaTrader_Jesse  
                            Started by U0000999, Today, 11:23 AM
                            0 responses
                            Last Post U0000999  
                            Started by James Wallace, Today, 10:38 AM
                            1 response
                            Last Post NinjaTrader_Zachary  
                            Started by mtamaku, Today, 10:22 AM
                            1 response
                            Last Post NinjaTrader_Jim  
                            Started by mtamaku, Today, 10:16 AM
                            4 responses
                            Last Post mtamaku
                            by mtamaku