Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw a dot at the top (or the bottom) of the price panel when a a condition is met

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

    Draw a dot at the top (or the bottom) of the price panel when a a condition is met

    I would like to draw a dot at the top of the price panel when a condition is met, but I would like to self adjust ( all of the dots) as the price changes in the graph.
    I hope I have made myself understand.
    FVJ

    #2
    Hello efeuvejota01,

    Thanks for your post.

    You could use the Draw.Dot() method to draw a dot object on a chart window. That draw object could then be moved programmatically by calling the Draw.Dot() method using the same exact tag name but with a different 'double y' argument.

    From the help guide linked below: "if you pass in a value of "myTag", each time this tag is used, the same draw object is modified. If unique tags are used each time, a new draw object will be created each time."

    For example, if you call Draw.Dot() with a tag name of "Dot1" and double y argument set to the recent Close[0] price, each time the Draw.Dot() method triggers in the script using that tag then that dot would move to the recent Close[0] price on the chart.

    See this help guide page for more information about Draw.Dot() and sample code: https://ninjatrader.com/support/help...8/draw_dot.htm

    Let me know if I may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thank you Brandon, let me try...

      Comment


        #4
        Thank you!!
        I got your point,
        The next question is how to know the actual "y" max value that is displayed in the chart, and, as the chart moves up and down, how to maintain the values of all dots in the chart at the max Y value...
        ??

        Comment


          #5
          Hello efeuvejota01,

          Thanks for your note.

          The Y value of the draw object will be set by you in the 'double y' argument when calling your Draw.Dot() method.

          For example, if you call Draw.Dot(this, "tag1", true, 0, Low[0], Brushes.Red); then the 'double y' argument of the draw object will be the current bar's Low price. Say the current Low price is 1000 when the Draw.Dot() method is called, the dot will be drawn at the Low price (1000).

          If the draw object is called again and moved on the next bar and the next bar's Low price is 950, the draw object 'double y' argument will reflect that Low price and the object will be drawn at the price 950 on that bar.

          Let me know if I may assist further.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            Thank you for your answer:
            What I mean is to do the following: I have edited the chart in paintbrush to move the test to the low of the viewable part of the chart

            FVJ

            Comment


              #7
              as complement with the following code
              Code:
                      protected override void OnBarUpdate()
                      {
                          //maxValue   = ChartScale;             //chartScale.MaxValue;
                          Draw.Dot(this, "Test"+CurrentBar, true, 0, maxValue, Brushes.Blue);
                      }
              
                      protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                      {        
                            // the maximum value of the chart scale
                          maxValue   = chartScale.MaxValue;
                      }
              ​
              I got the following result

              Comment


                #8
                Hello efeuvejota01,

                Thanks for your note.

                ChartScale.MaxValue could be used to get highest displayed value on the chart scale. Prints could be added to the script to print out ChartScale.MaxValue so you could see the value in a New > NinjaScript Output window.

                See this help guide page for more information about ChartScale.MaxValue and sample code: https://ninjatrader.com/support/help...e_maxvalue.htm

                Let me know if I may assist further.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #9
                  but I need the dots to be drawn in the panel 1... with Draw.Dot........ or something similar....
                  I tried several combinations and have had no luck...
                  Would you please tell me the syntax to be used in the OnBarUpdate of in the OnRender??
                  Thank you!!!
                  FVJ

                  Comment


                    #10
                    Hello efeuvejota01,

                    Thanks for your note.

                    Draw.Dot() can only be used in the OnBarUpdate() method, not in the OnRender() method.

                    If you would like to save the maximum value of the chart panel to a variable that could be used in OnBarUpdate(), you could assign ChartPanel.MaxValue to your variable in the OnBarUpdate() method. See below.

                    Code:
                    //class-level variable
                    private double maxValue;
                    
                    //OnBarUpdate
                    protected override void OnBarUpdate()
                    {
                        maxValue = ChartPanel.MaxValue;
                        Print("OnBarUpdate() maxValue" + maxValue);
                    
                        Draw.Dot(this, "tag1", true, 0, maxValue, Brushes.Cyan);
                    }​
                    See this help guide page for more information about ChartPanel.MaxValue: https://ninjatrader.com/support/help...chartpanel.htm

                    Ultimately, debugging prints should be added to the script to see exactly how each variable in your script is calculating. If the indicator is not functioning as you expect, add prints to the script that print out the values in your script to see how they are evaluating.

                    Prints will appear in a New > NinjaScript Editor.

                    Let me know if I may assist further.
                    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                    Comment


                      #11
                      Thank you!!
                      this shall work. I was usiing ChartScale instead ChartPanel
                      FVJ

                      Comment


                        #12
                        Appreciated Brandon:
                        I put in practice your advice and it worked partially, (very good at the historical part of the indicator, but aout of charts in the real time.
                        Let me show you the results:
                        Click image for larger version

Name:	Drawdots 3.jpg
Views:	274
Size:	59.2 KB
ID:	1223634Click image for larger version

Name:	Drawdots 4.jpg
Views:	254
Size:	55.2 KB
ID:	1223635Click image for larger version

Name:	Drawdots 5.jpg
Views:	250
Size:	55.3 KB
ID:	1223636
                        It turn out, that the dot is draw at the top of the chart but next bar it self adjust to let a margin between the dot and the max value.
                        I was not able to find where to find the top margin's value in order to subtracts it from the maxValue.
                        Any idea how to solve this??
                        FVJ

                        Comment


                          #13
                          Hello FVJ,

                          Thanks for your note.

                          This behavior could occur if the bool isAutoScale argument is set to true for the Draw method. You could set the isAutoScale argument to false to prevent this behavior.

                          Draw.Dot(): https://ninjatrader.com/support/help...8/draw_dot.htm

                          Let me know if I may further assist.
                          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                          Comment


                            #14
                            Thank you very much!!!!
                            FVJ

                            Comment


                              #15
                              Hello!!
                              It looks like the following chart suits the expectation I had.
                              Click image for larger version

Name:	MarginLowerHigher 3.jpg
Views:	240
Size:	44.7 KB
ID:	1223982
                              the code is as follows

                              Code:
                              namespace NinjaTrader.NinjaScript.Indicators.TestIndicators
                              {
                                  public class DrawDotsAtMinMaxPriceVA : Indicator
                                  {
                                      private double maxValue;
                                      protected override void OnStateChange()
                                      {
                                          if (State == State.SetDefaults)
                                          {
                                              Description                                    = @"Dibuja Puntos en la parte baja y alta de la grafica ";
                                              Name                                        = "DrawDotsAtMinMaxPriceVA";
                                              Calculate                                    = Calculate.OnBarClose;
                                              IsOverlay                                    = true; //este hay que ponerlo como true
                                              DisplayInDataBox                            = true;
                                              DrawOnPricePanel                            = false; //este hay que ponerlo como false esta para que dibuje en el mismo panel pero con diferente escala
                                              DrawHorizontalGridLines                        = true;
                                              DrawVerticalGridLines                        = true;
                                              PaintPriceMarkers                            = true;
                                              ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Overlay;// este puede ser overlay o left
                                              /* HERE is whereI woulkd like to set the upper an lower margins */
                                              //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                                              //See Help Guide for additional information.
                                              IsSuspendedWhileInactive                    = true;
                                          }
                                          else if (State == State.Configure)
                                          {        }
                                          else if (State == State.DataLoaded)
                                          {        }
                                      }
                              
                                      protected override void OnBarUpdate()
                                      {
                                          if (CurrentBar%2==0)
                                          {Draw.Dot(this, "Test3"+CurrentBar, true, 0, 1, Brushes.Blue);
                                          }
                                          else
                                          {Draw.Dot(this, "Test1"+CurrentBar, true, 0, 0, Brushes.Blue);
                                          }
                                      }
                              
                                      protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                                      {
                                      chartScale.Properties.AutoScaleMarginLower = 1.0;
                                      chartScale.Properties.AutoScaleMarginUpper = 1.0;
                                      }
                              
                                      #region Properties
                              
                                      [Browsable(false)]
                                      [XmlIgnore]
                                      public Series<double> Puntos
                                      {
                                          get { return Values[0]; }
                                      }
                                      #endregion
                              
                                  }
                              }
                              ​
                              Now the question:
                              Is there any way to suppress OnRender section, by declaring the MarginLower and the MarginUpper in the OnStateChange() section??

                              Thank you very much!!
                              FVJ

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              572 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              573 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X