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

Shade between two plots

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

    Shade between two plots

    Hi, I'm sure this is pretty easy to those that do it everyday.

    I have developed a simple indicator that has a "zone" either side of zero. This zone is delineated by two line "plots". For the sake of argument say the upper line is plotted at 0.8 and the lower at -0.5.

    How do I shade between these two plots using "opacity"?

    Thanks for your help;

    Ben.

    #2
    Hi Ben,

    This is done using DrawRegion(). There's a sample that can help use this available here:


    DrawRegion accepts opacity as an input. Opacity value ranges from 0 to 10.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi Ryan; I have tried your suggestion but it appears that the sample given fills between 2 DATA series on the main chart. I want to fill between 2 lines on a sub-indicator.


      protected override void Initialize()
      {
      Add(new Line(Color.Green, 0.4, "LongThreshold"));
      Add(new Line(Color.Red, -0.3, "ShortThreshold"));

      DrawRegion("Range Zone", CurrentBar, 0, LongThreshold, ShortThreshold, Color.Empty, Color.DarkGray, 8);

      This is what I have already, I want to fill between these two lines. Do I need to add a declaration to the variables?

      I am getting error: The name 'LongThreshold' does not exist in the current context.

      Have checked error code and it has suggested using 'int LongThreshold' but then it's looking for a value and the value is ?

      I don't know because it's set by the user or do I use a default of say 1 and -1.

      Thanks again;

      Ben.

      Comment


        #4
        Originally posted by stocktraderbmp View Post
        Hi Ryan; I have tried your suggestion but it appears that the sample given fills between 2 DATA series on the main chart. I want to fill between 2 lines on a sub-indicator.


        protected override void Initialize()
        {
        Add(new Line(Color.Green, 0.4, "LongThreshold"));
        Add(new Line(Color.Red, -0.3, "ShortThreshold"));

        DrawRegion("Range Zone", CurrentBar, 0, LongThreshold, ShortThreshold, Color.Empty, Color.DarkGray, 8);

        This is what I have already, I want to fill between these two lines. Do I need to add a declaration to the variables?

        I am getting error: The name 'LongThreshold' does not exist in the current context.

        Have checked error code and it has suggested using 'int LongThreshold' but then it's looking for a value and the value is ?

        I don't know because it's set by the user or do I use a default of say 1 and -1.

        Thanks again;

        Ben.
        NT does not have a construct for filling between 2 lines. At least one of the fill boundaries must be a DataSeries.

        Comment


          #5
          Yes, will need to convert one of those into a plot in order to use DrawRegion(). Plots can have static values like this so should still be able to do this.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            ok. as the plots are either side of a zero line, can we make the zero line a "data series" and then fill to the user variable plots?

            If yes, how do I do this simply?

            Comment


              #7
              Originally posted by stocktraderbmp View Post
              ok. as the plots are either side of a zero line, can we make the zero line a "data series" and then fill to the user variable plots?

              If yes, how do I do this simply?
              private DataSeries zeroLine;

              protected override void Initialize()
              {
              //
              this.zeroLine = new DataSeries(this);
              // ...
              }

              protected override void OnBarUpdate()
              {
              // ...
              this.zeroLine.Set(0);
              // ...
              }

              Comment


                #8
                Thanks for your help, hope this helps others too.

                Ben.

                Comment


                  #9
                  Sorry, can't get it to work and I've tried everything I can think of. Can you take a look at it please and make some suggestions or correct it.

                  File is attached.

                  Thanks for your time;

                  Ben.

                  Should have mentioned ... have removed the original plots, can't remember why but this is the script I was using for those:


                  protected override void Initialize()
                  {
                  Add(new Line(Color.Green, 1, "LongThreshold"));
                  Add(new Line(Color.Red, -1, "ShortThreshold"));


                  thanks again;

                  Ben
                  Last edited by stocktraderbmp; 10-18-2011, 06:59 AM.

                  Comment


                    #10
                    You posted an assembly, so no one will be able to comment on your source code.

                    Attached is an example that takes a couple inputs. These inputs can set upper and lower bounds as plots that are then used in DrawRegion().
                    Attached Files
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks for the examples all, have got it up and running.

                      Ben.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by TraderG23, 12-08-2023, 07:56 AM
                      9 responses
                      382 views
                      0 likes
                      Last Post Gavini
                      by Gavini
                       
                      Started by oviejo, Today, 12:28 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post oviejo
                      by oviejo
                       
                      Started by pechtri, 06-22-2023, 02:31 AM
                      10 responses
                      125 views
                      0 likes
                      Last Post Leeroy_Jenkins  
                      Started by judysamnt7, 03-13-2023, 09:11 AM
                      4 responses
                      59 views
                      0 likes
                      Last Post DynamicTest  
                      Started by ScottWalsh, Yesterday, 06:52 PM
                      4 responses
                      36 views
                      0 likes
                      Last Post ScottWalsh  
                      Working...
                      X