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

Can I use DrawRectangle/DrawRegion in the indicator panel?

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

    Can I use DrawRectangle/DrawRegion in the indicator panel?

    If so how do I do that?

    The other question I have if I can achieve the first issue is, how do I get the region to "extend" as long as the condition is true?

    Regards

    Kay Wai

    #2
    Yes Kai, provided you set DrawOnPricePanel to false - http://www.ninjatrader.com/support/h...pricepanel.htm

    You would run a counter for each bar that the condition is true and then extend your drawn region / rectangle - http://www.ninjatrader.com/support/f...ead.php?t=3419
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand, Thx for showing me how to draw on the indicator panel.

      I am unable to "extend" the DrawRectangle. Here is my code:
      Code:
      [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
      if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (result1 >= [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]60[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/COLOR]
      {
      markerisoverbought = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];
      [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (markerisoverbought == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
      {
      overboughtcounter++;
      [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ((overboughtcounter >=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]6[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) && (markerisoverbought == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))
      {
      DrawRectangle([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"OBPOQ"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], overboughtcounter, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]60[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]100[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], Color.Magenta, Color.Magenta, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);
      }
      }
      [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else
      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]{
      markerisoverbought = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];
      overboughtcounter = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];
      }
      }
      [/SIZE][/FONT][/SIZE][/FONT]
      Would you mind helping?

      Regards

      Kay Wai

      Comment


        #4
        Looks good to me Kai, though you could problably work in some loops making the code cleaner...
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I don't like the lines inside the rectangle and I would prefer a uniform fill which I am not getting because I'm using "CurrentBar" to draw the rectangle...just looking for ways to improve the aesthetics.

          Appreciate it if you could help.

          Comment


            #6
            Originally posted by kaywai View Post
            I don't like the lines inside the rectangle and I would prefer a uniform fill which I am not getting because I'm using "CurrentBar" to draw the rectangle...just looking for ways to improve the aesthetics.

            Appreciate it if you could help.
            What is your code line for the rectangles?

            Comment


              #7
              Originally posted by kaywai
              Here you go Koganam!

              I'm trying to achieve something similar to the attached image minus the line inbetween and the way the fill is displayed...is there an alternative to using CurrentBar?
              See if this cuts it.

              Code:
              			if (result1 >= 60)
              			{
              				******erisoverbought = true;
              				if (******erisoverbought == true)
              				{
              					overboughtcounter++;
              					if (overboughtcounter == 13)
              					{
              						OBRect = CurrentBar;
              						OBRectTag = "OBPOQ" + CurrentBar.ToString();
              					}
              					if ((overboughtcounter > 13))
              					{
              						DrawRectangle(OBRectTag, true, CurrentBar-OBRect, 60, 0, 100, Color.Transparent, Color.Magenta, 1);
              					}
              					else return;
              				}
              			...
              Notice that because part of your variable name (the Tom DeM... part) is copyrighted, the NT forum has substituted asterisks for that part of the string.

              Comment


                #8
                I understand totally Koganam! Thx much! Will try it out tonight!

                Comment


                  #9
                  NT,

                  I tried using drawRegion in OnMarketDepth this week and NT just logs an error and the indicator locks up.

                  Error - endBarsAgo out of valid range 0 through -1 was 0.

                  OnMarketData and OnBarUpdate are working fine with DrawRegion..

                  RJay
                  RJay
                  NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

                  Comment


                    #10
                    Hi Koganam,

                    The lines in the rectangle was faint but the color fill is darker on the left part of rectangle.

                    BTW I had to set up a OBRectTag variable...not sure how to do that! Lol!

                    Regards

                    Kay Wai

                    Comment


                      #11
                      Originally posted by kaywai View Post
                      Hi Koganam,

                      The lines in the rectangle was faint but the color fill is darker on the left part of rectangle.

                      BTW I had to set up a OBRectTag variable...not sure how to do that! Lol!

                      Regards

                      Kay Wai
                      Why do I not simply rewrite the file?

                      There are 3 additions: 1 in the variables section, 2 in the OnBarUpdate() method.
                      There are 2 changes, both in the OnBarUpdate() method.

                      The additions are clearly remarked in the file.

                      The file is attached. Just save your existing file to another name (if you really want to retain it), and copy this one over into the same folder as the original.
                      Attached Files

                      Comment


                        #12
                        Hi Koganam,

                        U da Man! Thx dude!

                        Regards

                        Kay Wai

                        Comment


                          #13
                          Using DrawRegion in Indicator Panel

                          Just a quick comment on the use of DrawRegion() in the Indicator panel when using the Default Initialize setting DrawOnPricePanel = true. You may "sandwich" in OnBarUpdate() a DrawRegion() function in between DrawOnPricePanel = false and DrawOnPricePanel = true and NT will draw all other objects in the Price panel but will fill the DrawRegion in the indicator panel.

                          #region Using declarations
                          using System;
                          using System.ComponentModel;
                          using System.Diagnostics;
                          using System.Drawing;
                          using System.Drawing.Drawing2D;
                          using System.Xml.Serialization;
                          using NinjaTrader.Cbi;
                          using NinjaTrader.Data;
                          using NinjaTrader.Gui.Chart;
                          #endregion

                          // This namespace holds all indicators and is required. Do not change it.
                          namespace NinjaTrader.Indicator
                          {
                          /// <summary>
                          /// Enter the description of your new custom indicator here
                          /// </summary>
                          [Description("Show that you can draw on both Price and Indicator Panels from the same indicator")]
                          public class DrawOnPriceAndIndicatorPanels : Indicator
                          {
                          #region Variables
                          // Wizard generated variables
                          // User defined variables (add any user defined variables below)
                          #endregion

                          /// <summary>
                          /// This method is used to configure the indicator and is called once before any bar data is loaded.
                          /// </summary>
                          protected override void Initialize()
                          {
                          Add(new Plot(Color.FromKnownColor(KnownColor.ActiveCaption Text), PlotStyle.Line, "PlotMACD"));
                          Add(new Line(Color.FromKnownColor(KnownColor.Gold), 0, "Zero"));
                          Overlay = false;
                          }

                          /// <summary>
                          /// Called on each bar update event (incoming tick)
                          /// </summary>
                          protected override void OnBarUpdate()
                          {
                          if(CurrentBar<26) return;
                          // Use this method for calculating your indicator values. Assign a value to each
                          // plot below by replacing 'Close[0]' with your own formula.
                          Value.Set(MACD(26,9,3)[0]);

                          //Draw Vertical Line on Price Panel first time MACD>0
                          if (Value[1]<=0 && Value[0]>0)
                          DrawVerticalLine("MACD>0"+CurrentBar,0,Color.Green ) ;


                          //Draw Vertical Line on Price Panel first time MACD<0
                          if (Value[1]>=0 && Value[0]<0)
                          DrawVerticalLine("MACD<0"+CurrentBar,0,Color.Red) ;


                          //Now fill the region between MACD and x axis in the Indicator Panel
                          DrawOnPricePanel = false ;//Switch to draw on Indicator Panel
                          DrawRegion("MACD"+CurrentBar,1,0,Value,0,Color.Tra nsparent,Value[0]>0?Color.Green:Color.Red,5);
                          DrawOnPricePanel = true; //Restore default setting for next Bar Update.

                          }

                          #region Properties
                          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                          public DataSeries PlotMACD
                          {
                          get { return Values[0]; }
                          }

                          #endregion
                          }
                          }
                          Attached Files

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by andrewtrades, Today, 04:57 PM
                          1 response
                          10 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by chbruno, Today, 04:10 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post chbruno
                          by chbruno
                           
                          Started by josh18955, 03-25-2023, 11:16 AM
                          6 responses
                          436 views
                          0 likes
                          Last Post Delerium  
                          Started by FAQtrader, Today, 03:35 PM
                          0 responses
                          9 views
                          0 likes
                          Last Post FAQtrader  
                          Started by rocketman7, Today, 09:41 AM
                          5 responses
                          20 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Working...
                          X