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

Plotting vertical zones

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

    Plotting vertical zones

    Hi guys, I was wondering what the best approach would be to plot vertical fixed zones? For example from 0 to 1 in green, from 1 to 2 blue, ... At the moment I'm doing this by plotting bars with the width set to a value big enough so they overlap. This is working fine but I'm not sure if this is the right or the best approach to do this.

    #2
    Hello Vanderbeke,

    Thanks for your post.

    You might try using Draw.RegionHighlightX() for vertical zones or Draw.RegionHighLightY() for horizontal zones (which is what I think you are looking for).

    References:

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul

      This is exactly what I was looking for. Thanks!

      Comment


        #4
        Hi Paul, I was a bit too fast with my answer. Your solution is perfect for drawing zones on the chart. But my intention is to draw these zones inside my indicator which is located under the chart. Is there any similar solution for this?

        Comment


          #5
          Hello Vanderbeke,

          Thanks for your reply.

          Perhaps I am not understanding but the references I provided are for use in an indicator as these are methods you can use in ninjascript to draw the zones. (They also happen to be available as drawing tools through the charts drawing tool icon).
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Hi Paul

            Below is an excerpt of the code mentioned on the info page. For the coördinates, information of the bars is used. But my inidicator has values from 0 to 5 because it has its own window with a separate scale. Could you give me an example how this will work? Perhaps using the MACD indicator as an example. Everything above null in green, and everthing beneath in red?

            Draw.RegionHighlightY(this, "tag1", High[0], Low[0], Brushes.Blue, Brushes.Green, 20);

            Comment


              #7
              Hello Vanderbeke,

              Thanks for your reply.

              The example in the helpguide is incorrect, it is missing a parameter. We will update the helpguide example shortly.

              In the case of your indicator, you could do something like this:

              if (CurrentBar == 0)
              {
              Draw.RegionHighlightY(this, "test", true, 0, 5, Brushes.LightBlue, Brushes.Blue, 20);
              Draw.RegionHighlightY(this, "test1", true, 0, -5, Brushes.LightPink, Brushes.Pink, 20);
              }


              On the first bar loaded it draws the zones once.
              Attached Files
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Hi Paul

                I must be doing something wrong because when I add your code to the indicator it is showing zones on the chart and not on the indicator. Below an example of the MACD indicator where I added your code.



                Code:
                		protected override void OnBarUpdate()
                		{
                			double input0	= Input[0];
                
                			if (CurrentBar == 0)
                			{	
                				fastEma[0]		= input0;
                				slowEma[0]		= input0;
                				Value[0]		= 0;
                				Avg[0]			= 0;
                				Diff[0]			= 0;
                			}
                			else
                			{
                				double fastEma0	= constant1 * input0 + constant2 * fastEma[1];
                				double slowEma0	= constant3 * input0 + constant4 * slowEma[1];
                				double macd		= fastEma0 - slowEma0;
                				double macdAvg	= constant5 * macd + constant6 * Avg[1];
                
                				fastEma[0]		= fastEma0;
                				slowEma[0]		= slowEma0;
                				Value[0]		= macd;
                				Avg[0]			= macdAvg;
                				Diff[0]			= macd - macdAvg;
                			}
                
                            if (CurrentBar == 0)
                            {
                                Draw.RegionHighlightY(this, "test", true, 0, 5, Brushes.LightBlue, Brushes.Blue, 20);
                                Draw.RegionHighlightY(this, "test1", true, 0, -5, Brushes.LightPink, Brushes.Pink, 20);
                            }
                        }

                Comment


                  #9
                  Hello Vanderbeke,

                  Thanks for your reply.

                  Unless otherwise specified, draw objects will be drawn on the price panel.

                  To change that behavior, in the OnStateChange() method, within State.SetDefaults, please add the statement: DrawOnPricePanel = false; // draw objects in the indicator's panel

                  Reference: https://ninjatrader.com/support/help...pricepanel.htm
                  Paul H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by adeelshahzad, Today, 03:54 AM
                  4 responses
                  25 views
                  0 likes
                  Last Post adeelshahzad  
                  Started by merzo, 06-25-2023, 02:19 AM
                  10 responses
                  823 views
                  1 like
                  Last Post NinjaTrader_ChristopherJ  
                  Started by frankthearm, Today, 09:08 AM
                  5 responses
                  17 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  43 views
                  0 likes
                  Last Post jeronymite  
                  Started by yertle, Today, 08:38 AM
                  5 responses
                  16 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Working...
                  X