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

DrawRegion colors disappear when I restart

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

    DrawRegion colors disappear when I restart

    Hello,

    I built an indicator which works well, all calc bugs removed as far as I know...
    - see 1st attached image

    However, when I shut down NinjaTrader and then restart the next day the colors in the indicator plot disappear and everything is gray.
    - see 2nd attached image

    If I refresh the chart everything is still gray. I noticed if I edit the indicator parameters, the up color / down color inputs are EMPTY...
    - see 2nd attached image

    From there I can select a new color and it works... so it appears my set colors are being replaced with "empty" when I shut down (or start up)? Does anyone have any idea how to fix this?


    Code:
            #region Variables
    	private Color upColor = Color.YellowGreen;
    	private Color dnColor = Color.DarkOrange;
    	private Color lineColor = Color.Gainsboro;
    	#endregion
    
    				if (CurrentBar == 0)
    					return;
    				
    				if (Values[0][0] >= 0)
    				{
    					DrawRegion("Zone" + CurrentBar, 1, 0, Values[0], 0, Color.FromArgb(8,upColor), upColor, 4);
    					
    				}
    				else if (Values[0][0] <= 0)
    				{
    					DrawRegion("Zone" + CurrentBar, 1, 0, Values[0], 0, Color.FromArgb(8,dnColor), dnColor, 4);
    				}
    
            #region Properties
    	[Description("Up Color")]
            [GridCategory("Parameters")]
    		[Gui.Design.DisplayName ("\tUp Color")]
            public Color UpColor
            {
                get { return upColor; }
                set { upColor = value; }
            }
    		
            [Description("Down Color")]
            [GridCategory("Parameters")]
    		[Gui.Design.DisplayName ("Down Color")]
            public Color DownColor
            {
                get { return dnColor; }
                set { dnColor = value; }
            }
            #endregion
    Attached Files

    #2
    Originally posted by ntfred View Post
    Hello,

    I built an indicator which works well, all calc bugs removed as far as I know...
    - see 1st attached image

    However, when I shut down NinjaTrader and then restart the next day the colors in the indicator plot disappear and everything is gray.
    - see 2nd attached image

    If I refresh the chart everything is still gray. I noticed if I edit the indicator parameters, the up color / down color inputs are EMPTY...
    - see 2nd attached image

    From there I can select a new color and it works... so it appears my set colors are being replaced with "empty" when I shut down (or start up)? Does anyone have any idea how to fix this?


    Code:
            #region Variables
        private Color upColor = Color.YellowGreen;
        private Color dnColor = Color.DarkOrange;
        private Color lineColor = Color.Gainsboro;
        #endregion
     
                    if (CurrentBar == 0)
                        return;
     
                    if (Values[0][0] >= 0)
                    {
                        DrawRegion("Zone" + CurrentBar, 1, 0, Values[0], 0, Color.FromArgb(8,upColor), upColor, 4);
     
                    }
                    else if (Values[0][0] <= 0)
                    {
                        DrawRegion("Zone" + CurrentBar, 1, 0, Values[0], 0, Color.FromArgb(8,dnColor), dnColor, 4);
                    }
     
            #region Properties
        [Description("Up Color")]
            [GridCategory("Parameters")]
            [Gui.Design.DisplayName ("\tUp Color")]
            public Color UpColor
            {
                get { return upColor; }
                set { upColor = value; }
            }
     
            [Description("Down Color")]
            [GridCategory("Parameters")]
            [Gui.Design.DisplayName ("Down Color")]
            public Color DownColor
            {
                get { return dnColor; }
                set { dnColor = value; }
            }
            #endregion
    If you want your colors to persist across restarts, then you have to serialize them.

    If you search the forum for the phrase: "serialize color", you should eventually come upon this thread: http://www.ninjatrader.com/support/f...ead.php?t=4977

    Comment


      #3
      It worked! Thanks for the help koganam, I really don't think I would have figured that one out on my own.

      For anyone interested, here's what the new serialized code looks like:
      Code:
              [COLOR="blue"][XmlIgnore][/COLOR]
      	[Description("Up Color")]
              [GridCategory("Parameters")]
      	[Gui.Design.DisplayName ("\tUp Color")]
              public Color UpColor
              {
                  get { return upColor; }
                  set { upColor = value; }
              }
      	// Serialize Color object
      	[COLOR="blue"][Browsable(false)]
      	public string UpColorSerialize
      	{
      		get { return NinjaTrader.Gui.Design.SerializableColor.ToString(upColor); }
      		set { upColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
      	}[/COLOR]
      		
              [COLOR="blue"][XmlIgnore][/COLOR]
              [Description("Down Color")]
              [GridCategory("Parameters")]
      	[Gui.Design.DisplayName ("Down Color")]
              public Color DownColor
              {
                  get { return dnColor; }
                  set { dnColor = value; }
              }
      	// Serialize Color object
      	[COLOR="blue"][Browsable(false)]
      	public string DnColorSerialize
      	{
      		get { return NinjaTrader.Gui.Design.SerializableColor.ToString(dnColor); }
      		set { dnColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
      	}[/COLOR]

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      44 views
      0 likes
      Last Post jeronymite  
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      20 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      179 views
      0 likes
      Last Post jeronymite  
      Started by ghoul, Today, 06:02 PM
      0 responses
      10 views
      0 likes
      Last Post ghoul
      by ghoul
       
      Started by DanielSanMartin, Yesterday, 02:37 PM
      2 responses
      13 views
      0 likes
      Last Post DanielSanMartin  
      Working...
      X