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 xiinteractive, 04-09-2024, 08:08 AM
            2 responses
            10 views
            0 likes
            Last Post xiinteractive  
            Started by Irukandji, Today, 09:34 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by RubenCazorla, Today, 09:07 AM
            1 response
            5 views
            0 likes
            Last Post RubenCazorla  
            Started by TraderBCL, Today, 04:38 AM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by WeyldFalcon, 08-07-2020, 06:13 AM
            11 responses
            1,423 views
            0 likes
            Last Post jculp
            by jculp
             
            Working...
            X