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

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

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

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

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

                    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:	170
Size:	59.2 KB
ID:	1223634Click image for larger version

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

Name:	Drawdots 5.jpg
Views:	156
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.
                          Brandon H.NinjaTrader Customer Service

                          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:	162
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 usasugardefender, Today, 01:42 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post usasugardefender  
                              Started by haas88, 03-21-2024, 02:22 AM
                              15 responses
                              182 views
                              0 likes
                              Last Post haas88
                              by haas88
                               
                              Started by brianfnoel, Today, 01:24 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post brianfnoel  
                              Started by bill2023, Yesterday, 08:21 AM
                              2 responses
                              14 views
                              0 likes
                              Last Post bill2023  
                              Started by ynoldsany, Today, 01:00 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post ynoldsany  
                              Working...
                              X