Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to fill zone between moving averages?

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

    How to fill zone between moving averages?

    Hi. Good morning for everybody.

    I have two moving averages and i need to fill the zone between them.

    Above cross, one color. Below cross, other color. If possible, change the color of the line as well.


    Thanks!!!

    #2
    Hello testingsarasa,

    Thanks for your post.

    To color the area between moving averages you can use: Draw.Region() Here is a link to the helpguide for that: https://ninjatrader.com/support/help...raw_region.htm

    To color the plots themselves, you would use PlotBrushes[][], please see the helpguide here (which includes an example of changing based on rising/falling conditions): https://ninjatrader.com/support/help...lotbrushes.htm

    You may be interested either in using or in studying the code of this indicator which provides the options to color two moving averages and optionally provides the ability to color the region between the two moving averages: https://ninjatrader.com/support/foru...d=7&linkid=906

    Comment


      #3
      Originally posted by NinjaTrader_Paul View Post
      Hello testingsarasa,

      Thanks for your post.

      To color the area between moving averages you can use: Draw.Region() Here is a link to the helpguide for that: https://ninjatrader.com/support/help...raw_region.htm

      To color the plots themselves, you would use PlotBrushes[][], please see the helpguide here (which includes an example of changing based on rising/falling conditions): https://ninjatrader.com/support/help...lotbrushes.htm

      You may be interested either in using or in studying the code of this indicator which provides the options to color two moving averages and optionally provides the ability to color the region between the two moving averages: https://ninjatrader.com/support/foru...d=7&linkid=906


      Paul, thanks for always answering.

      I have those errors, how can I cast from ISeries <double> to double?

      CODE:

      HTML Code:
      Values[1][0]=EMA(Closes[1], 5)[0];
      	Values[2][0]=EMA(Opens[1], 5)[0];
      And the drawing tool gives those errors but I do not know why they are.
      Last edited by testingsarasa; 05-31-2018, 06:51 AM.

      Comment


        #4
        Hello testingsarasa,

        Thanks for your reply.

        I am missing the context of the error messages, are these from an indicator you are working on? The Column to the left of the error messages would show the file that the errors are associated with.

        What version of NinjaTrader8 are you using? (Check under Help>About).

        Comment


          #5
          Originally posted by NinjaTrader_Paul View Post
          Hello testingsarasa,

          Thanks for your reply.

          I am missing the context of the error messages, are these from an indicator you are working on? The Column to the left of the error messages would show the file that the errors are associated with.

          What version of NinjaTrader8 are you using? (Check under Help>About).
          8.0.13.1 64-bit

          it's my version of NT8.

          Comment


            #6
            Hello testingsarasa,

            Thanks for your reply.

            Can you post your entire code? If possible, please just post the .CS file as that would be easier to review.

            Comment


              #7
              Originally posted by NinjaTrader_Paul View Post
              Hello testingsarasa,

              Thanks for your reply.

              Can you post your entire code? If possible, please just post the .CS file as that would be easier to review.
              HTML Code:
              //This namespace holds Indicators in this folder and is required. Do not change it. 
              namespace NinjaTrader.NinjaScript.Indicators.MyIndicator
              {
              	public class MyIndicator: Indicator
              	{
              		protected override void OnStateChange()
              		{
              			if (State == State.SetDefaults)
              			{
              				Description									= @"My Indicator developed in ninja";
              				Name										= "MyIndicator";
              				Calculate									= Calculate.OnBarClose;
              				IsOverlay									= true;
              				DisplayInDataBox							= true;
              				DrawOnPricePanel							= true;
              				DrawHorizontalGridLines						= true;
              				DrawVerticalGridLines						= true;
              				PaintPriceMarkers							= true;
              				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
              				//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;
              				Displacement 								= 0;
              				MaximumBarsLookBack 						= MaximumBarsLookBack.Infinite;
              				
              			}
              			
              			else if (State == State.Configure)
              			{
              				AddDataSeries(BarsPeriodType.Minute, 60);
              				AddDataSeries(BarsPeriodType.Minute, 60);
              				
              				AddPlot(Brushes.Transparent, "Primary");			
              
              				AddPlot(Brushes.Red, "Second");	
              				AddPlot(Brushes.Aqua,"Third");
              			}
              			
              		}
              		
              		protected override void OnBarUpdate()
              		{
              			
              			if(CurrentBars[1] <20 || CurrentBars[0]<20  || CurrentBars[2]<20 ) return;
              			
              			Values[0][0]=DEMA(Opens[0], 5)[0];
              			Values[1][0]=DEMA(Closes[1], 5)[0];
              			Values[2][0]=DEMA(Opens[1], 5)[0];
              			
              			
              			if(Values[2][0]>Values[1][0])
              			{
              				Draw.Region(this, "tag1", CurrentBar, 0, Values[1][0], Values[2][0], null, Brushes.Aqua, 50);
              			}
              		}
              	}
              }
              Last edited by testingsarasa; 05-31-2018, 07:12 AM.

              Comment


                #8
                Hello testingsarasa,

                Thanks for your reply.

                What are valueOpen and valueClose? I do not see them declared or assigned anywhere.

                For Draw.region, which method overload are you using? Your parameter sequence (and type of) need to match the chosen overload used.

                If I may suggest, you may find it easier to learn using a single data series.

                Comment


                  #9
                  Originally posted by NinjaTrader_Paul View Post
                  Hello testingsarasa,

                  Thanks for your reply.

                  What are valueOpen and valueClose? I do not see them declared or assigned anywhere.

                  For Draw.region, which method overload are you using? Your parameter sequence (and type of) need to match the chosen overload used.

                  If I may suggest, you may find it easier to learn using a single data series.
                  My fault, sorry. I tested something and not worked haha

                  the line is this: Draw.Region(this, "tag1", CurrentBar, 0, Values[1][0], Values[2][0], null, Brushes.Aqua, 50);

                  For Draw.region, i used the example in the documentation

                  Comment


                    #10
                    Hello testingsarasa,

                    Thanks for your reply.

                    The example in the helpguide is using two data series to draw between. Using Values[1][0], Values[2][0] is the same as using single values, try using DEMA(Closes[1], 5) and DEMA(Opens[1], 5)[0];

                    Comment


                      #11
                      Originally posted by NinjaTrader_Paul View Post
                      Hello testingsarasa,

                      Thanks for your reply.

                      The example in the helpguide is using two data series to draw between. Using Values[1][0], Values[2][0] is the same as using single values, try using DEMA(Closes[1], 5) and DEMA(Opens[1], 5)[0];
                      Thanks to you. I tried and it did not work with those parameters.

                      Comment


                        #12
                        Hello testingsarasa,

                        Thanks for your reply.

                        Sorry, I made a copy/paste mistake, instead of DEMA(Opens[1], 5)[0] use DEMA(Opens[1], 5)

                        Comment


                          #13
                          Originally posted by NinjaTrader_Paul View Post
                          Hello testingsarasa,

                          Thanks for your reply.

                          Sorry, I made a copy/paste mistake, instead of DEMA(Opens[1], 5)[0] use DEMA(Opens[1], 5)
                          Compile but do not fill the area.

                          if(CrossAbove(DEMA(Opens[1], 5), DEMA(Closes[1], 5), 2))
                          {
                          Draw.Region(this, "tag1", CurrentBar, 0, DEMA(Opens[1], 5), DEMA(Closes[1], 5), null, Brushes.Aqua, 90, 0);
                          }

                          Comment


                            #14
                            Hello testingsarasa,

                            Thanks for your reply.

                            I've re-created, using a single data series and it plots without issue so I suspect the issue is related to your multi time frame coding. You may need to add a BarsInProgress check, for example:

                            if (BarsInProgress != 0) return; // only plot on chart bars

                            if(CrossAbove(DEMA(Opens[1], 5), DEMA(Closes[1], 5), 2))
                            {
                            Draw.Region(this, "tag1", CurrentBar, 0, DEMA(Opens[1], 5), DEMA(Closes[1], 5), null, Brushes.Aqua, 90, 0);
                            }
                            Attached Files

                            Comment


                              #15
                              Draw.Region(this, "Tag" + nRegionStart, nCount, 0, LongTrend, MidTrend, Brushes.Transparent, pCloudUpColor, nOpacity);

                              the nRegionStart is when crossed. I use this for my tags in order to reduce multiple graphics

                              if (bCloudSwitchGreen == true)
                              {
                              Draw.Region(this, "Tag" + nRegionStart, nCount, 0, LongTrend, MidTrend, Brushes.Transparent, pCloudUpColor, nOpacity);
                              nCount++;
                              }
                              if (bCloudSwitchGreen == false)
                              {
                              Draw.Region(this, "Tag" + nRegionStart, nCount, 0, LongTrend, MidTrend, Brushes.Transparent, pCloudDownColor, nOpacity);
                              nCount++;
                              }


                              my long and midtrend are my plots
                              Last edited by ballboy11; 05-31-2018, 04:43 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              612 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              355 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              561 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              564 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X