Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Most resource-efficient way to NOT display a Plot()

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

    Most resource-efficient way to NOT display a Plot()

    I've written a simple indicator which displays bar numbers.

    Because I want a quick way to turn the indicator on and off, I put my own button on the tool bar and I override the Plot() function to display the bar numbers (or not), without needing to reload all Ninjascript to get the change.

    Now I decided I need to show the bar number in the data box, so I can see it when I'm not displaying it directly on the chart below the bar.

    So I figure I need Plot in my indie, which up to now I don't have, and I'll set DisplayInDataBox to true.

    What is the most resource efficient way of setting up the new Plot? Shall I have an invisible color, or some other way?

    #2
    Hello adamus,

    Using transparent on a plot will cause the plot to not actually draw. This would be more efficient than using any color though I could not say by how much.

    You do have the option of using DrawText/DrawTextFixed to display this outside of the databox if you are not wanting to plot this. However, this would not allow you to look back a historical value by moving the mouse over a historical bar.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      OK, good to know. Thanks v. much.

      Comment


        #4
        I just tried this, and I must be missing something.

        * I do set the value in OnBarUpdate: Value[0] = CurrentBar;
        * That does how up in the Data Box, as desired
        * It also puts a visible plot on the chart -- so on to the next step

        * I set the color transparent in Initialize(), as suggested
        *The good news is that does indeed avoid drawing the unwanted line on the chart
        * The bad news is that it also blanks out the value in Data Box. The entry is there
        in Data Box, but the value part is blank.

        What am I missing? My goal is to do as the OP wanted to -- find a way to display the bar number in Data Box without also creating a visible line on the chart.

        --EV

        Comment


          #5
          OK -- problem solved (mostly):
          • OnBarUpdate() set the value
          • Dummy Plot() routine, so it will not actually get plotted
            • Setting transparent does not work well -- it makes the data box value blank

          • User has to configure display in data box TRUE and price marker FALSE

          That works exactly as desired. The only fly in the ointment is that the user should not have to do any configuration. Is there a way for the indicator to set those two things (display in data box and not display price marker)? Anything I have tried fails to solve that.

          -- EV

          Comment


            #6
            Oooops ... the solution I posted has a big problem. NT allows room in the chart for the bar number line, even though it is not actually being plotted. I am looking at SPY right now -- flat-lined along the bottom of the chart. The problem is that SPY closed at 186.20, but bar #4586! 185 is not very high on a chart that goes to 4586, even with a log price axis.

            Back to the drawing board. Does anyone know any way to get the bar number displayed in the Data Box?

            --EV

            Comment


              #7
              Hi ETFVoyageur

              try these settings in Initialize:

              AutoScale = false;
              PaintPriceMarkers = false;

              Actually you might have to alter your Plot() because you want to print the bar number on the screen rather than display a chart for it. My code here has a few extra snippets that I need, but you should see how Plot() either does or doesn't call graphics.DrawText()

              Code:
              #region Using declarations
              using System;
              using System.ComponentModel;
              using System.Drawing;
              using System.Windows.Forms;
              using System.Text;
              using System.Diagnostics;
              using System.Drawing.Drawing2D;
              using System.Xml.Serialization;
              using NinjaTrader.Cbi;
              using NinjaTrader.Data;
              using NinjaTrader.Gui.Design;
              using NinjaTrader.Gui.Chart;
              
              
              #endregion
              
              namespace NinjaTrader.Indicator
              {
                  [Gui.Design.DisplayName("PermaCode Bar Numbers")]
                  [Description("Numbering of bars in the chart.")]
                  public class PermaCodeBarNumbers : Indicator
                  {
                      private ToolStrip toolStrip = null;
                      private ToolStripButton toolStripButton = null;
                      private ToolStripSeparator toolStripSeparator = null;    
                      public enum Placement { Top, Bottom };
                      private Color textColor = Color.Gray;
                      private Font textFont = new Font("Verdana", 6F);
                      private Placement numberPlacement = Placement.Bottom;
                      private int offset = 15; 
                      private double y;
                      private int modulus = 3;
                      private int sessionBar;
                      private int increment = 1;
                      private int start = 1;
                      private bool enabled = true;
                      private SolidBrush brush;
                      private StringFormat format;
                      private bool useSession = true;
                      
                      protected override void Initialize()
                      {
                          CalculateOnBarClose    = true;
                          Overlay = true;
                          BarsRequired = 0;
                          AutoScale = false;
                          PaintPriceMarkers = false;
                          Add(new Plot(Color.Aqua, "Bar Numbers"));
                      }
                      
                      protected override void OnStartUp()
                      {
                          Control[] control = ChartControl.Controls.Find("tsrTool", false);
                          if(control != null && control.Length > 0) 
                          {
                              toolStripButton = new ToolStripButton("Bar #'s");
                              toolStripButton.Name = "BarNumbersButton";
                              toolStripButton.Click += ButtonClick;
                              toolStrip = (ToolStrip) control[0];
                              toolStrip.Items.Add(toolStripButton);
                          }
                          brush = new SolidBrush(textColor);
                          format = new StringFormat();
                          format.Alignment = StringAlignment.Center;
                          sessionBar = start;
                      }
              
                      protected override void OnTermination()
                      {
                          if(toolStrip != null && toolStripButton != null)
                          {
                              toolStrip.Items.RemoveByKey("BarNumbersButton");
                              toolStripButton.Dispose();
                              toolStripButton = null;
                              toolStrip = null;
                          }
                          brush.Dispose();
                          format.Dispose();
                          base.Dispose();
                      }
                      
                      private void ButtonClick(object s, EventArgs e) 
                      {
                          enabled = !enabled;
                          ChartControl.ChartPanel.Refresh();
                      }
                      
                      protected override void OnBarUpdate()
                      {
                          if (useSession && Bars.FirstBarOfSession)
                          {
                              sessionBar = start * increment;
                          }
                          Value.Set(Math.Floor((double) (sessionBar) / increment));
                          sessionBar++;
                      }
              
                      public override string FormatPriceMarker(double price)
                      {
                          return price.ToString("0");
                      }
                      
                      public override void Plot(Graphics graphics, Rectangle bounds, 
                          double min, double max)
                      {
                          if (Bars == null || ChartControl == null)
                              return;
                          int oldBarNumber = 0, barNumber = 0;
                          for (int x = FirstBarIndexPainted; enabled && x <= LastBarIndexPainted; x++)
                          {
                              oldBarNumber = barNumber;
                              barNumber = (int) Value.Get(x);
                              if (barNumber != oldBarNumber && (barNumber * increment % modulus) == 0)
                              {
                                  int leftX = ChartControl.GetXByBarIdx(Bars, x);
                                  int textY = 0; 
                                  if (numberPlacement == Placement.Top)
                                  {
                                      // top < bottom
                                      textY = ChartControl.GetYByValue(this, 
                                          High[CurrentBar - x]) - offset - textFont.Height; 
                                  }
                                  else
                                  {
                                      textY = ChartControl.GetYByValue(this, 
                                          Low[CurrentBar - x]) + offset;
                                  }
                                  graphics.DrawString(barNumber + "", 
                                      textFont, brush, leftX, textY, format);
                              }
                          }
                      }
              Last edited by adamus; 03-24-2014, 04:56 AM.

              Comment


                #8
                Hi ETFVoyageur,

                You are right... setting to transparent removes it from the data box...

                Ok, instead try adding the indicator (without setting it to transparent) to its own panel and then maximizing the data series panel.

                This basically hides it from the chart but still shows the values in the data box.

                To maximize a panel (the price panel with the data series), right-click the price margin -> select Maximize.

                (This will hide all additional panels as well)
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by adamus View Post
                  Hi ETFVoyageur

                  try these settings in Initialize:

                  AutoScale = false;
                  PaintPriceMarkers = false;

                  Actually you might have to alter your Plot() because you want to print the bar number on the screen rather than display a chart for it. My code here has a few extra snippets that I need, but you should see how Plot() either does or doesn't call graphics.DrawText()
                  Thank you for your suggestion. That did it. It now works perfectly -- DataBox now shows the bar number. All related issues are clean.

                  That will be a big help at certain times. I already had the ability to draw bar numbers on the screen, but they are often so crowded they are not readable (when bars are close together).

                  --EV
                  Last edited by ETFVoyageur; 03-24-2014, 01:37 PM.

                  Comment


                    #10
                    Originally posted by NinjaTrader_ChelseaB View Post
                    Hi ETFVoyageur,

                    You are right... setting to transparent removes it from the data box...

                    Ok, instead try adding the indicator (without setting it to transparent) to its own panel and then maximizing the data series panel.

                    This basically hides it from the chart but still shows the values in the data box.

                    To maximize a panel (the price panel with the data series), right-click the price margin -> select Maximize.

                    (This will hide all additional panels as well)
                    What works for me is to override Plot() and do not plot that line.

                    --EV

                    Comment


                      #11
                      Originally posted by ETFVoyageur View Post
                      Oooops ... the solution I posted has a big problem. NT allows room in the chart for the bar number line, even though it is not actually being plotted. I am looking at SPY right now -- flat-lined along the bottom of the chart. The problem is that SPY closed at 186.20, but bar #4586! 185 is not very high on a chart that goes to 4586, even with a log price axis.

                      Back to the drawing board. Does anyone know any way to get the bar number displayed in the Data Box?

                      --EV
                      Use AutoScale = false; for the indicator. You might also want to put it on the other axis using ScaleJustification.Left or ScaleJustification.Overlay.

                      ref: http://www.ninjatrader.com/support/h.../autoscale.htm

                      Comment


                        #12
                        Originally posted by koganam View Post
                        Use AutoScale = false; for the indicator. You might also want to put it on the other axis using ScaleJustification.Left or ScaleJustification.Overlay.

                        ref: http://www.ninjatrader.com/support/h.../autoscale.htm
                        http://www.ninjatrader.com/support/h...tification.htm
                        Thanks for the suggestion.

                        AutoScale=false is what Adamus suggested. It did indeed help.

                        EV

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        581 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        338 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        103 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        554 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        552 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X