Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to fill zone between moving averages?

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

    #16
    Originally posted by ballboy11 View Post
    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
    Thanks ballboy11 I appreciate you sharing your code. I got mine to work based on this, but used "CurrentBar - nRegionStart" instead of "nCount".

    Comment


      #17
      Came to this thread because I was having issues changing the region's colors at the crossing of two indicators. That's done now (thanks ballboy11 and NinjaTrader_PaulH).

      I also wanted to change colors within the area/region (in between crossings) depending on the direction of one indicator, but I found that it would be creating too many objects and affect performance. Any ideas would be appreciated. For example: a fast EMA crossing up a slower EMA, the area/region is drawn green, but when it starts falling, the color switches to a darker green (still green until it crosses down). Probably not worth the effort or compute resources but people like the visual effects.

      Comment


        #18
        2 things. It is great you got it working. First you would have to check if ema0 is less than ema1 to change color, second nRegionstart can be reset to zero in order to save object memory

        Comment


          #19
          hello,
          I am also in search of the same indicator which can fill color between 2 moving average.... can you please post the .cs file?
          thanks

          Comment


            #20
            i copied the code from here but i am full of erorrs.....

            //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);
            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++;
            }}
            }
            }
            }

            #region NinjaScript generated code. Neither change nor remove.

            namespace NinjaTrader.NinjaScript.Indicators
            {
            public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
            {
            private MyIndicator.MyIndicator[] cacheMyIndicator;
            public MyIndicator.MyIndicator MyIndicator()
            {
            return MyIndicator(Input);
            }

            public MyIndicator.MyIndicator MyIndicator(ISeries<double> input)
            {
            if (cacheMyIndicator != null)
            for (int idx = 0; idx < cacheMyIndicator.Length; idx++)
            if (cacheMyIndicator[idx] != null && cacheMyIndicator[idx].EqualsInput(input))
            return cacheMyIndicator[idx];
            return CacheIndicator<MyIndicator.MyIndicator>(new MyIndicator.MyIndicator(), input, ref cacheMyIndicator);
            }
            }
            }

            namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
            {
            public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
            {
            public Indicators.MyIndicator.MyIndicator MyIndicator()
            {
            return indicator.MyIndicator(Input);
            }

            public Indicators.MyIndicator.MyIndicator MyIndicator(ISeries<double> input )
            {
            return indicator.MyIndicator(input);
            }
            }
            }

            namespace NinjaTrader.NinjaScript.Strategies
            {
            public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
            {
            public Indicators.MyIndicator.MyIndicator MyIndicator()
            {
            return indicator.MyIndicator(Input);
            }

            public Indicators.MyIndicator.MyIndicator MyIndicator(ISeries<double> input )
            {
            return indicator.MyIndicator(input);
            }
            }
            }

            #endregion

            Comment


              #21
              Here is the file for you and what you are trying to do. It will work. It looks like you want to compare with the 60 minute chart and what other time frame you are trading with MyIndicator.zip

              Comment


                #22
                Originally posted by ballboy11 View Post
                here is the file for you and what you are trying to do. It will work. It looks like you want to compare with the 60 minute chart and what other time frame you are trading with [ATTACH]n1057757[/ATTACH]
                i want to place it on 75 tick chart, and need sma 20/70 band
                thakns
                Last edited by hir04068; 05-17-2019, 04:37 AM.

                Comment


                  #23
                  Originally posted by ballboy11 View Post
                  Here is the file for you and what you are trying to do. It will work. It looks like you want to compare with the 60 minute chart and what other time frame you are trading with [ATTACH]n1057757[/ATTACH]
                  hello,
                  I can't see an option to put sma period in the indicator?

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  605 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  351 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
                  560 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  561 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X