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

Color as a parameter

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

    Color as a parameter

    Hi.
    I want to be able to set bar color from an input parameter. I have tried -

    variables
    private Color buyBarColor = Color.Blue;

    Properties
    [Description("Color for Buy Bars")]
    [GridCategory("Parameters")]
    public Color BuyBarColor
    {
    get { return buyBarColor; }
    set { buyBarColor = value; }
    }

    I get a nice blue colored box in the indicator parameters section, and the
    bars are colored blue by BarColor = BuyBarColor;. Any color can be chosen at this point but when Ninja is closed and re-opened, the blue setting (or whatever color was set) has been lost.
    Is there any solution to this please?
    Dave

    #2
    Hello DaveS,

    Thank you for your post.

    There is a second segment of code that would need to be used for these to serialize property when saving your workspace.

    Please try adding the following below your current code:

    Code:
    [Browsable(false)] 
    public string BuyBarColorSerialize
    {      
    get { return NinjaTrader.Gui.Design.SerializableColor.ToString(buyBarColor); }      
    set { buyBarColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
    
     }
    Please see our Reference Sample on User Definable Color Inputs for more information:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Color as Parameter

      Hallo, I' m sorry but this code doesn't work:
      /// <summary>
      /// </summary>
      [XmlIgnore]
      [Description("Select Color for TargetLineColor")]
      [Category("Parameters")]
      [Gui.Design.DisplayName("TargetLineColor")]
      public Color TargetLineColor
      {
      get { return targetLineColor; }
      set { targetLineColor = value; }
      }

      // Serialize Color object
      [Browsable(false)]
      public string TargetLineColorSerialize
      {
      get { returnNinjaTrader.Gui.Design.SerializableColor.ToS tring(targetLineColor);}
      set { targetLineColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
      }

      Thanks Rolf Theus

      Comment


        #4
        Hello RolfTheus,

        Welcome to the NinjaTrader Support Forums!

        I see a few formatting errors that may be causing issues.

        Originally posted by RolfTheus View Post
        Hallo, I' m sorry but this code doesn't work:
        /// <summary>
        /// </summary>
        [XmlIgnore]
        [Description("Select Color for TargetLineColor")]
        [Category("Parameters")]
        [Gui.Design.DisplayName("TargetLineColor")]
        public Color TargetLineColor
        {
        get { return targetLineColor; }
        set { targetLineColor = value; }
        }

        // Serialize Color object
        [Browsable(false)]
        public string TargetLineColorSerialize
        {
        get { returnNinjaTrader.Gui.Design.SerializableColor.ToS tring(targetLineColor);}
        set { targetLineColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
        }

        Thanks Rolf Theus
        There are a few spaces and one in need of a space that will be causing issues. You may see the following code below:

        Code:
        		[XmlIgnore]
        		[Description("Select Color for TargetLineColor")]
        		[Category("Parameters")]
        		[Gui.Design.DisplayName("TargetLineColor")]
        		public Color TargetLineColor
        		{
        		get { return targetLineColor; }
        		set { targetLineColor = value; }
        		}
        
        		// Serialize Color object
        		[Browsable(false)]
        		public string TargetLineColorSerialize
        		{
        		get { return NinjaTrader.Gui.Design.SerializableColor.ToString(targetLineColor);} 
        		set { targetLineColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
        		}
        Coding is very case and format sensitive, you may view the following link from our Help Guide that goes over some tutorials and concepts at the following link.
        http://www.ninjatrader.com/support/h..._resources.htm

        Let us know if we can be of further assistance.
        JCNinjaTrader Customer Service

        Comment


          #5
          Thank you for answering, but the spaces are product of copying. I tried to format the code in the Messagearea. I could compile my code. I have copied your code, and now it works fine. But what is the difference except the spaces ? I don't know.

          Thanks
          Rolf Theus

          Comment


            #6
            Hello RolfTheus,

            I did not change anything inside the code that you posted besides add a space between "return" and "NinjaTrader.Gui(...)", remove the space between the "ToS" and "tring" in the same line, and remove the space between "FromStrin" and "g" in the next line.
            JCNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Radano, 06-10-2021, 01:40 AM
            20 responses
            615 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by Mizzouman1, Today, 07:35 AM
            0 responses
            4 views
            0 likes
            Last Post Mizzouman1  
            Started by i019945nj, 12-14-2023, 06:41 AM
            6 responses
            66 views
            0 likes
            Last Post i019945nj  
            Started by aa731, Today, 02:54 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by BarzTrading, Today, 07:25 AM
            0 responses
            3 views
            0 likes
            Last Post BarzTrading  
            Working...
            X