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

Draw region, simple but complicated for a beginner

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

    Draw region, simple but complicated for a beginner

    Hello,

    sorry for my English which is not a language that I master (thanks Google).

    I've been trying for a few days, by going through forum posts especially, to place a colored area in an indicator that I found on a platform. (thanks to its creator)

    My idea was simple, to have a color zone between my high Donchian channel 100 and the one at 50 and a color zone between my low Donchian channel 100 and 50.
    Not succeeding in combining the two I got my hands on a indicator grouping the two Donchian channels into a single code.

    I'm trying to use Draw Region, but I don't understand how or where. I just want a simple modification but it's a gas plant!

    I peeled the help, various message and download indicators which color the regions to understand, but I always have errors and if I post today it is good for a last resort.

    I don't want to learn to code, to have a simple colored region on my graph.​

    I'm using the MaCrossBuilder indicator as an example as well, and although I noted the lines of codes, I don't understand what I need to change​


    https://ninjatraderecosystem.com/use...color-regions/
    https://ninjatrader.com/support/help...t8/?region.htm





    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class TASCDonchianNT8 : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"";
                    Name                                        = "TASCDonchianNT8";
                    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;
    
                    Len1                                        = 100;
                    Len2                                        = 50;
                }
                else if (State == State.Configure)
                {
                    AddPlot(Brushes.Green, "LongUpper");
                    AddPlot(Brushes.Violet, "ShortUpper");
                    AddPlot(Brushes.Violet, "ShortLower");
                    AddPlot(Brushes.Green, "LongLower");
                }
            }
    
            protected override void OnBarUpdate()
            {
                Values[0][0] = MAX(High, Len1)[0];
                Values[1][0] = MAX(High, Len2)[0];
                Values[2][0] = MIN(Low, Len2)[0];
                Values[3][0] = MIN(Low, Len1)[0];
            }
    
            #region Properties
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Len1", GroupName = "NinjaScriptParameters", Order = 0)]
            public int Len1
            { get; set; }
    
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Len2", GroupName = "NinjaScriptParameters", Order = 0)]
            public int Len2
            { get; set; }
            #endregion
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private TASCDonchianNT8[] cacheTASCDonchianNT8;
            public TASCDonchianNT8 TASCDonchianNT8(int len1, int len2)
            {
                return TASCDonchianNT8(Input, len1, len2);
            }
    
            public TASCDonchianNT8 TASCDonchianNT8(ISeries<double> input, int len1, int len2)
            {
                if (cacheTASCDonchianNT8 != null)
                    for (int idx = 0; idx < cacheTASCDonchianNT8.Length; idx++)
                        if (cacheTASCDonchianNT8[idx] != null && cacheTASCDonchianNT8[idx].Len1 == len1 && cacheTASCDonchianNT8[idx].Len2 == len2 && cacheTASCDonchianNT8[idx].EqualsInput(input))
                            return cacheTASCDonchianNT8[idx];
                return CacheIndicator<TASCDonchianNT8>(new TASCDonchianNT8(){ Len1 = len1, Len2 = len2 }, input, ref cacheTASCDonchianNT8);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.TASCDonchianNT8 TASCDonchianNT8(int len1, int len2)
            {
                return indicator.TASCDonchianNT8(Input, len1, len2);
            }
    
            public Indicators.TASCDonchianNT8 TASCDonchianNT8(ISeries<double> input , int len1, int len2)
            {
                return indicator.TASCDonchianNT8(input, len1, len2);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.TASCDonchianNT8 TASCDonchianNT8(int len1, int len2)
            {
                return indicator.TASCDonchianNT8(Input, len1, len2);
            }
    
            public Indicators.TASCDonchianNT8 TASCDonchianNT8(ISeries<double> input , int len1, int len2)
            {
                return indicator.TASCDonchianNT8(input, len1, len2);
            }
        }
    }
    
    #endregion
    ​

    #2
    Hello Max238,

    To draw a region you would need to use Draw.Region after the plots have been set in OnBarUpdate. In what you provided that would be after this line:

    Code:
    Values[3][0] = MIN(Low, Len1)[0];
    //your region code here
    There are some samples of making regions in the following link:





    I don't want to learn to code, to have a simple colored region on my graph.​

    This is a programming forum for programming questions, if you don't want to learn to code you can also reach out to third party developers to have items made for you. If you wanted more information on that topic please let me know.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for his information NinjaTrader Jesse
      I wish you a good day​

      Comment


        #4
        Hello everyone, I started coding this indicator again.
        I've made progress in the coding, but here's what I can do for the top channel, I can't do it for the bottom channel.
        I don't understand why it doesn't stop at channel 20 low!​

        Click image for larger version

Name:	rgiob haut colorer.png
Views:	187
Size:	81.9 KB
ID:	1270706
        Caption

        Click image for larger version

Name:	bas colorer.png
Views:	142
Size:	105.8 KB
ID:	1270707
        Caption


        Code:
        amespace NinjaTrader.NinjaScript.Indicators.Favoris
        {
            public class TASCDonchianLowNT8 : Indicator
            {
                protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
                        Description                                    = @"";
                        Name                                        = "TASCDonchianLowNT8";
                        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;
        
                        Len1                                        = 50;
                        AddPlot(Brushes.Red, "Court haut");
                        AddPlot(Brushes.Red, "Long bas");
        
        
                        Len2                                        = 20;
                        AddPlot(Brushes.Green, "Court bas");
                        AddPlot(Brushes.Green, "Long haut");
        
                        ///Regiona Between MA'a
                        ColorRegions                = true;
                        ColorRegionAbove            = Brushes.Blue;
                        ColorRegionBelow            = Brushes.Orange;
                        RegionOpacity                = 20;
        
        
                    }
                }
        
                protected override void OnBarUpdate()
                {
                    Values[0][0] = MAX(High, Len1)[0];
                    Values[1][0] = MAX(High, Len2)[0];
                    Values[2][0] = MIN(Low, Len2)[0];
                    Values[3][0] = MIN(Low, Len1)[0];
        
        
                ///Region Between Lower, Upper
                if (ColorRegions)
                {
                //if (CrossDetect[0] == 1 || (savedUBar > savedDBar))
                {
                Draw.Region(this, "tag1", CurrentBar, 0, Value, Upper, null, ColorRegionAbove, RegionOpacity);
                }
                if (ColorRegions)
                {
                Draw.Region(this, "tag2", CurrentBar, 0, Value, Lower, null, ColorRegionBelow, RegionOpacity);
                }
              }
            }    
        
        
                #region Properties
                [Range(1, int.MaxValue), NinjaScriptProperty]
                [Display(ResourceType = typeof(Custom.Resource), Name = "Len1", GroupName = "NinjaScriptParameters", Order = 0)]
                public int Len1
                { get; set; }
        
        
                [Range(1, int.MaxValue), NinjaScriptProperty]
                [Display(ResourceType = typeof(Custom.Resource), Name = "Len2", GroupName = "NinjaScriptParameters", Order = 0)]
                public int Len2
                { get; set; }
        
        
        
                ///Regions
                [Display(Name="Color region between MAs", Order=60, GroupName="Regions")]
                [RefreshProperties(RefreshProperties.All)]
                public bool ColorRegions
                { get; set; }            
        
                [XmlIgnore]
                [Display(Name="Region color for fast above slow", Order=61, GroupName="Regions")]
                public Brush ColorRegionAbove
                { get; set; }
        
                [Browsable(false)]
                public string ColorRegionAboveSerializable
                {
                get { return Serialize.BrushToString(ColorRegionAbove); }
                set { ColorRegionAbove = Serialize.StringToBrush(value); }
                }    
        
                [XmlIgnore]
                [Display(Name="Region color for fast below slow ", Order=62, GroupName="Regions")]
                public Brush ColorRegionBelow
                { get; set; }
        
                [Browsable(false)]
                public string ColorRegionBelowSerializable
                {
                get { return Serialize.BrushToString(ColorRegionBelow); }
                set { ColorRegionBelow = Serialize.StringToBrush(value); }
                }
        
                [Range(1, 99)]
                [Display(Name=" % Opacity of region", Order=63, GroupName="Regions")]
                public int RegionOpacity
                { get; set; }        
        
                [Browsable(false)]
                [XmlIgnore()]
                public Series<double> Lower
                {
                    get { return Values[2]; }
                }
        
                [Browsable(false)]
                [XmlIgnore()]
                public Series<double> Upper
                {
                    get { return Values[1]; }
                }
        
        
        
                #endregion
            }​

        Comment


          #5
          Hello Max238,

          Which two plots are you trying to have the second region draw between, would that be the following two plots?

          AddPlot(Brushes.Red, "Court haut");
          AddPlot(Brushes.Green, "Court bas");

          If you wanted the two green plots:

          AddPlot(Brushes.Green, "Court bas");
          AddPlot(Brushes.Green, "Long haut");​

          You need to change the draw region to use
          Values[2]
          Values[3]
          JesseNinjaTrader Customer Service

          Comment


            #6
            Hello Jesse, thank you for your response.

            I also think that in his lines is where my solution lies, but after several tests I only found a headache.

            I'll try that again when I have time.

            Comment


              #7
              Damn, why is the language so complicated!

              Under another platform it barely took me a few minutes,
              I've been testing it for several days, nothing works

              It's simple though !

              Two channels of 20 and 50 each with a high and low color.

              I managed to put the color on the top part as you could see on the screen, but impossible on the bottom one !

              Grr !

              Comment


                #8
                Hello Max238,

                Again I need to know what two specific plots you want to color between, right now the second region is coloring the first plot which is AddPlot(Brushes.Red, "Court haut"); and the other plot is AddPlot(Brushes.Green, "Court bas");.

                If you had intended to color between the two green plots you don't have the correct code, you need to use Values[2] and Values[3]​ in the second draw region.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello Jesse,

                  Yes I tried to color the region between the two green bands.

                  I tried to change Value 2 and 3 but either I have an error or I completely lose the color.

                  I'll try something else another time, it's too tiring for me.

                  Comment


                    #10
                    Hello, again with this indicator which still gives me the same problem! Except this time it no longer colors any region even though it is activated! Can you help me ?

                    HTML Code:
                    #region Using declarations
                    using System;
                    using System.Collections.Generic;
                    using System.ComponentModel;
                    using System.ComponentModel.DataAnnotations;
                    using System.Linq;
                    using System.Text;
                    using System.Threading.Tasks;
                    using System.Windows;
                    using System.Windows.Input;
                    using System.Windows.Media;
                    using System.Xml.Serialization;
                    using NinjaTrader.Cbi;
                    using NinjaTrader.Gui;
                    using NinjaTrader.Gui.Chart;
                    using NinjaTrader.Gui.SuperDom;
                    using NinjaTrader.Gui.Tools;
                    using NinjaTrader.Data;
                    using NinjaTrader.NinjaScript;
                    using NinjaTrader.Core.FloatingPoint;
                    using NinjaTrader.NinjaScript.DrawingTools;
                    #endregion
                    
                    //This namespace holds Indicators in this folder and is required. Do not change it.
                    namespace NinjaTrader.NinjaScript.Indicators.Favoris
                    {
                        public class TASCDonchianNT8 : Indicator
                        {
                            protected override void OnStateChange()
                            {
                                if (State == State.SetDefaults)
                                {
                                    Description                                    = @"";
                                    Name                                        = "TASCDonchianNT8";
                                    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;
                                    
                                    Len1                                        = 50;
                                    AddPlot(Brushes.Red, "Long haut");
                                    AddPlot(Brushes.Red, "Court haut");
                                    
                                    
                                    Len2                                        = 20;
                                    AddPlot(Brushes.Green, "Court bas");
                                    AddPlot(Brushes.Green, "Long bas");
                                    
                                    ///Regiona Between MA'a
                                    ColorRegions                = false;
                                    ColorRegionAbove            = Brushes.Blue;
                                    ColorRegionBelow            = Brushes.Orange;
                                    RegionOpacity                = 30;
                            
                    
                                }
                            }
                    
                            protected override void OnBarUpdate()
                            {
                                Values[0][0] = MAX(High, Len1)[0];    //Canal 50 haut
                                Values[1][0] = MAX(High, Len2)[0];    //Canal 20 haut
                                Values[2][0] = MIN(Low, Len2)[0];    //Canal 50 bas
                                Values[3][0] = MIN(Low, Len1)[0];    //Canal 20 bas
                                
                                            
                            ///Region Between Lower, Middle, Upper
                            if (ColorRegions)
                            {
                            //if (CrossDetect[0] == 1 || (savedUBar > savedDBar))
                            {
                            Draw.Region(this, "tag1", CurrentBar, 0, Value, Upper, null, ColorRegionAbove, RegionOpacity);
                            }
                            if (ColorRegions)
                            {
                            Draw.Region(this, "tag2", CurrentBar, 0, Value, Lower, null, ColorRegionBelow, RegionOpacity);
                            }
                          }
                        }    
                            
                            
                            #region Properties
                            [Range(1, int.MaxValue), NinjaScriptProperty]
                            [Display(ResourceType = typeof(Custom.Resource), Name = "Len1", GroupName = "NinjaScriptParameters", Order = 0)]
                            public int Len1
                            { get; set; }
                    
                    
                            [Range(1, int.MaxValue), NinjaScriptProperty]
                            [Display(ResourceType = typeof(Custom.Resource), Name = "Len2", GroupName = "NinjaScriptParameters", Order = 0)]
                            public int Len2
                            { get; set; }
                            
                            
                            ///Regions
                            [Display(Name="Color region between MAs", Order=60, GroupName="Regions")]
                            [RefreshProperties(RefreshProperties.All)]
                            public bool ColorRegions
                            { get; set; }            
                            
                            [XmlIgnore]
                            [Display(Name="Region color for fast above slow", Order=61, GroupName="Regions")]
                            public Brush ColorRegionAbove
                            { get; set; }
                    
                            [Browsable(false)]
                            public string ColorRegionAboveSerializable
                            {
                            get { return Serialize.BrushToString(ColorRegionAbove); }
                            set { ColorRegionAbove = Serialize.StringToBrush(value); }
                            }    
                            
                            [XmlIgnore]
                            [Display(Name="Region color for fast below slow ", Order=62, GroupName="Regions")]
                            public Brush ColorRegionBelow
                            { get; set; }
                    
                            [Browsable(false)]
                            public string ColorRegionBelowSerializable
                            {
                            get { return Serialize.BrushToString(ColorRegionBelow); }
                            set { ColorRegionBelow = Serialize.StringToBrush(value); }
                            }
                    
                            [Range(1, 99)]
                            [Display(Name=" % Opacity of region", Order=63, GroupName="Regions")]
                            public int RegionOpacity
                            { get; set; }        
                            
                            [Browsable(false)]
                            [XmlIgnore()]
                            public Series <double> Upper
                            {
                                get { return Values[0]; }
                            }
                            
                            [Browsable(false)]
                            [XmlIgnore()]
                            public Series <double> Lower
                            {
                                get { return Values[1]; }
                            }
                            
                            
                            
                            #endregion
                        }
                    }
                    
                    #region NinjaScript generated code. Neither change nor remove.
                    
                    namespace NinjaTrader.NinjaScript.Indicators
                    {
                        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                        {
                            private Favoris.TASCDonchianNT8[] cacheTASCDonchianNT8;
                            public Favoris.TASCDonchianNT8 TASCDonchianNT8(int len1, int len2)
                            {
                                return TASCDonchianNT8(Input, len1, len2);
                            }
                    
                            public Favoris.TASCDonchianNT8 TASCDonchianNT8(ISeries<double> input, int len1, int len2)
                            {
                                if (cacheTASCDonchianNT8 != null)
                                    for (int idx = 0; idx < cacheTASCDonchianNT8.Length; idx++)
                                        if (cacheTASCDonchianNT8[idx] != null && cacheTASCDonchianNT8[idx].Len1 == len1 && cacheTASCDonchianNT8[idx].Len2 == len2 && cacheTASCDonchianNT8[idx].EqualsInput(input))
                                            return cacheTASCDonchianNT8[idx];
                                return CacheIndicator<Favoris.TASCDonchianNT8>(new Favoris.TASCDonchianNT8(){ Len1 = len1, Len2 = len2 }, input, ref cacheTASCDonchianNT8);
                            }
                        }
                    }
                    
                    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
                    {
                        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
                        {
                            public Indicators.Favoris.TASCDonchianNT8 TASCDonchianNT8(int len1, int len2)
                            {
                                return indicator.TASCDonchianNT8(Input, len1, len2);
                            }
                    
                            public Indicators.Favoris.TASCDonchianNT8 TASCDonchianNT8(ISeries<double> input , int len1, int len2)
                            {
                                return indicator.TASCDonchianNT8(input, len1, len2);
                            }
                        }
                    }
                    
                    namespace NinjaTrader.NinjaScript.Strategies
                    {
                        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
                        {
                            public Indicators.Favoris.TASCDonchianNT8 TASCDonchianNT8(int len1, int len2)
                            {
                                return indicator.TASCDonchianNT8(Input, len1, len2);
                            }
                    
                            public Indicators.Favoris.TASCDonchianNT8 TASCDonchianNT8(ISeries<double> input , int len1, int len2)
                            {
                                return indicator.TASCDonchianNT8(input, len1, len2);
                            }
                        }
                    }
                    
                    #endregion
                    ​

                    Comment


                      #11
                      Hello Max238,

                      Did you set the user input ColorRegions to true in the user interface when you applied the script? You have a default value of false so it should not draw anything unless you are manually changing the value to true when you apply it.

                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Hello Jesse, Yes it is activated
                        Click image for larger version

Name:	indic.jpg
Views:	24
Size:	87.2 KB
ID:	1298216

                        Comment


                          #13
                          Well forget it, I've been working on it for months and it still doesn't work. I'm going to change to Prorealtime I know that my indicator works there.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by f.saeidi, Today, 05:56 AM
                          1 response
                          3 views
                          0 likes
                          Last Post Jltarrau  
                          Started by Jltarrau, Today, 05:57 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post Jltarrau  
                          Started by Stanfillirenfro, Yesterday, 09:19 AM
                          7 responses
                          51 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by TraderCro, 04-12-2024, 11:36 AM
                          4 responses
                          70 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Mindset, Yesterday, 02:04 AM
                          1 response
                          15 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Working...
                          X