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

How to override Plot after terminal starting?

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

    How to override Plot after terminal starting?

    Hello

    I have this code:

    Code:
        public class BackGroundGradient : Indicator
        {
            #region Variables
            public Color CL_1         = Color.DimGray; //Color.Lavender;
            public Color CL_2        = Color.Black; //Color.LightSkyBlue;
               private Rectangle bounds;
            private int max;
            private int min;
            private Graphics graphics;
    
            
            internal Color Color1;
            internal Color Color2;
        
            private DataSeries MAHolder;
            private int Period = 42;
            #endregion
    
            #region Initialize & OnBarUpdate
            protected override void Initialize()
            {
                Overlay                = true;
                CalculateOnBarClose = true;
                MAHolder = new DataSeries(this);
                
            public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
    {
                if (Bars == null)
                    return;
            {            
            base.Plot(graphics,bounds,min,max);
                /*
                if(High[0] > MAHolder[0] && Low[0] > MAHolder[0])
                {
                    Color2 = FadeColour ;//Color.PaleGoldenrod;
                    Color1 = LongColour;// Color.DodgerBlue;
                }
                else if(Low[0] < MAHolder[0] && High[0] < MAHolder[0])
                {
                    Color2 = FadeColour ;// Color.PaleGoldenrod;
                    Color1 = ShortColour;// Color.Firebrick;
                }
                else
                {
                Color2 = Color.Transparent;
                Color1 = Color.Yellow;
                }*/
    
                Color1 = CL_1;
                Color2 = CL_2;
                
            /* For full explanation of below please see
                http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.blend.aspx    
            */
                //float[] relativeIntensities = { 0.7f, 0.5f, 0.7f, 0.5f, 0.1f };//original
                float[] relativeIntensities = { 0.2f, 0.4f, 0.8f, 0.8f, 0.4f,0.2f };//top to bottom - higher nos = higher amt of Color2
    
                float[] relativePositions   = { 0.0f, 0.2f, 0.4f, 0.6f,0.8f, 1.0f };// change these to alter 'mix'NB must match array number above
    
                Blend myBlend         = new Blend();
                myBlend.Factors     = relativeIntensities;
                myBlend.Positions    = relativePositions;
        
                LinearGradientBrush linGrBrush = new LinearGradientBrush (
                new Point(0, bounds.X),
                new Point(0,bounds.Width),
                Color1,
                Color2);
                linGrBrush.Blend = myBlend;
                
                Pen pen = new Pen(linGrBrush);    
                
                graphics.FillRectangle(linGrBrush,bounds);// simplified
                this.ZOrder = -1;        
            
            }
     
      }            
                    
            }
            
            
            protected override void OnBarUpdate()
            { 
                //MAHolder.Set(EMA(Period)[0]);
            }
            
            #endregion
            
            #region Plot Override
            public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
    {
                if (Bars == null)
                    return;
            {            
            base.Plot(graphics,bounds,min,max);
                /*
                if(High[0] > MAHolder[0] && Low[0] > MAHolder[0])
                {
                    Color2 = FadeColour ;//Color.PaleGoldenrod;
                    Color1 = LongColour;// Color.DodgerBlue;
                }
                else if(Low[0] < MAHolder[0] && High[0] < MAHolder[0])
                {
                    Color2 = FadeColour ;// Color.PaleGoldenrod;
                    Color1 = ShortColour;// Color.Firebrick;
                }
                else
                {
                Color2 = Color.Transparent;
                Color1 = Color.Yellow;
                }
                */
            
                Color1 = CL_1;
                Color2 = CL_2;
                
            /* For full explanation of below please see
                http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.blend.aspx    
            */
                //float[] relativeIntensities = { 0.7f, 0.5f, 0.7f, 0.5f, 0.1f };//original
                float[] relativeIntensities = { 0.2f, 0.4f, 0.8f, 0.8f, 0.4f,0.2f };//top to bottom - higher nos = higher amt of Color2
    
                float[] relativePositions   = { 0.0f, 0.2f, 0.4f, 0.6f,0.8f, 1.0f };// change these to alter 'mix'NB must match array number above
    
                Blend myBlend         = new Blend();
                myBlend.Factors     = relativeIntensities;
                myBlend.Positions    = relativePositions;
        
                LinearGradientBrush linGrBrush = new LinearGradientBrush (
                new Point(0, bounds.X),
                new Point(0,bounds.Width),
                Color1,
                Color2);
                linGrBrush.Blend = myBlend;
                
                Pen pen = new Pen(linGrBrush);    
                
                graphics.FillRectangle(linGrBrush,bounds);// simplified
                this.ZOrder = -1;        
            
            }
     
      }
    #endregion
    
            #region Properties
    
            [Description("EMA Period")]
            [NinjaTrader.Gui.Design.DisplayName("EMA length")]
            [Category ("Parameters")]
            public int period
    
            {
                get {return Period;}
                set {Period = value;}
            }
            
            [XmlIgnore]// very important
            [Category("Text & Colors")]
            public Color longColour
            {
                get { return CL_1; }
                set { CL_1 = value; }
            }
            
            [XmlIgnore]
            [Browsable(false)]
            public string longColourSerialize
            {
                get { return NinjaTrader.Gui.Design.SerializableColor.ToString(CL_1); }
                set { CL_1 = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
            }
            
            [XmlIgnore]
            [Category("Text & Colors")]
            public Color fadeColour
            {
                get { return CL_2; }
                set { CL_2 = value; }
            }
            
            [XmlIgnore]
            [Browsable(false)]
            public string FadeColourSerialize
            {
                get { return NinjaTrader.Gui.Design.SerializableColor.ToString(CL_2); }
                set { CL_2 = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
            }
            /*
            [XmlIgnore]
            [Category("Text & Colors")]
            public Color shortColour
            {
                get { return ShortColour; }
                set { ShortColour = value; }
            }
            
            [XmlIgnore]
            [Browsable(false)]
            public string ShortColourSerialize
            {
                get { return NinjaTrader.Gui.Design.SerializableColor.ToString(ShortColour); }
                set { ShortColour = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
            }
            */
    #endregion
        }
    There is override Plot

    Situation is:
    1. I save workspace, exit from NT
    2. I start NT and i see charts, which is in saved workspace and this indicator on chart, but Plot doesn't override after starting terminal - why?

    #2
    Hello agafon2,

    Thank you for you post.

    Are there any error messages listed in the Log tab of the NinjaTrader Control Center upon start up?

    If so please detail them in your response.

    I look forward to your response.

    Comment


      #3
      There are Default errors:

      SaveImg &#1087;&#1086;&#1079;&#1074;&#1086;&#1083;&#1080;&#1090; &#1074;&#1072;&#1084; &#1079;&#1072;&#1075;&#1088;&#1091;&#1079;&#1080;&#1090;&#1100; &#1092;&#1086;&#1090;&#1086; &#1080;&#1083;&#1080; &#1082;&#1072;&#1088;&#1090;&#1080;&#1085;&#1082;&#1091; &#1073;&#1077;&#1089;&#1087;&#1083;&#1072;&#1090;&#1085;&#1086; &#1080; &#1073;&#1077;&#1079; &#1088;&#1077;&#1075;&#1080;&#1089;&#1090;&#1088;&#1072;&#1094;&#1080;&#1080;

      Comment


        #4
        Hello agafon2,

        Thank you for your response.

        Please send me your log and trace files for today so that I may look into what occurred.

        You can do this by going to the Control Center-> Help-> Mail to Support.

        Please place 'ATTN: Patrick - 801428' in the subject line and reference this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=56271

        I look forward to your response.

        Comment


          #5
          Originally posted by NinjaTrader_PatrickH View Post
          Hello agafon2,

          Thank you for your response.

          Please send me your log and trace files for today so that I may look into what occurred.

          You can do this by going to the Control Center-> Help-> Mail to Support.

          Please place 'ATTN: Patrick - 801428' in the subject line and reference this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=56271

          I look forward to your response.
          This is an indicator in attachment. Please, try to launch it in your NT and make a restart of NT and look into Log.
          Attached Files

          Comment


            #6
            Hello agafon2,

            Thank you for your response.

            Within the Properties region of the code you have the serialization set to XmlIgnore:
            Code:
                    [B][XmlIgnore][/B]
                    [Browsable(false)]
                    public string longColourSerialize
                    {
                        get { return NinjaTrader.Gui.Design.SerializableColor.ToString(CL_1); }
                        set { CL_1 = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
                    }
            This is incorrect, you want to set the Color to XmlIgnore but not the string:
            Code:
            [XmlIgnore]// very important
                    [Category("Text & Colors")]
                    public Color longColour
                    {
                        get { return CL_1; }
                        set { CL_1 = value; }
                    }
                    
                    [Browsable(false)]
                    public string longColourSerialize
                    {
                        get { return NinjaTrader.Gui.Design.SerializableColor.ToString(CL_1); }
                        set { CL_1 = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
                    }
            Please remove the [XmlIgnore] before the string for each color and advise if on restart your indicator shows the correct colors.

            Comment


              #7
              Originally posted by NinjaTrader_PatrickH View Post
              Hello agafon2,

              Thank you for your response.

              Within the Properties region of the code you have the serialization set to XmlIgnore:
              Code:
                      [B][XmlIgnore][/B]
                      [Browsable(false)]
                      public string longColourSerialize
                      {
                          get { return NinjaTrader.Gui.Design.SerializableColor.ToString(CL_1); }
                          set { CL_1 = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
                      }
              This is incorrect, you want to set the Color to XmlIgnore but not the string:
              Code:
              [XmlIgnore]// very important
                      [Category("Text & Colors")]
                      public Color longColour
                      {
                          get { return CL_1; }
                          set { CL_1 = value; }
                      }
                      
                      [Browsable(false)]
                      public string longColourSerialize
                      {
                          get { return NinjaTrader.Gui.Design.SerializableColor.ToString(CL_1); }
                          set { CL_1 = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
                      }
              Please remove the [XmlIgnore] before the string for each color and advise if on restart your indicator shows the correct colors.
              Can you explain, when and why we should use XmlIgnore in properties?

              Comment


                #8
                Hello agafon2,

                Thank you for your response.

                XmlIgnore gets or sets a value that specifies whether or not the XmlSerializer serializes a public field or public read/write property.

                This is needed to serialize the colors, but the colors need the string for the serialization as well. For information on the serialization of colors please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=4977

                For information on XmlIgnore please visit the following link: http://msdn.microsoft.com/en-us/libr...xmlignore.aspx

                Please let me know if I may be of further assistance.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by chbruno, Today, 04:10 PM
                0 responses
                1 view
                0 likes
                Last Post chbruno
                by chbruno
                 
                Started by josh18955, 03-25-2023, 11:16 AM
                6 responses
                436 views
                0 likes
                Last Post Delerium  
                Started by FAQtrader, Today, 03:35 PM
                0 responses
                6 views
                0 likes
                Last Post FAQtrader  
                Started by rocketman7, Today, 09:41 AM
                5 responses
                19 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by frslvr, 04-11-2024, 07:26 AM
                9 responses
                127 views
                1 like
                Last Post caryc123  
                Working...
                X