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

Change Brushes color from the script interface

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

    Change Brushes color from the script interface

    Hi Ninjatrader team.

    I am trying to change the color of the ellipse from the script interface.
    I have another parameter under enum and it works correctly
    but it seems that "Brushes" does not support enum configuration manually.
    This is the closest I have come.

    Code:
    
        public enum DirectionBar
            {
                BarUP,
                BarDown,
            }
    
    
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class Example1 : Strategy
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                          ("Default settings omitted for forum transcript")
    
                    ControlBar                                    = DirectionBar.BarUP;
                    ColorElipse                                    = Brushes.Green;
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                //Add your custom strategy logic here.
    
                if (ControlBar == DirectionBartolo.BarUP
                && Open[0] < Close[0])
                    {
                        Draw.Ellipse(this, "MyEllipseUP" + CurrentBar, 1, Low[0] -3 * TickSize, -1, High[0]    +3* TickSize, ColorElipse);
    
                    }
            }
    
    
    
                [NinjaScriptProperty]
                [Display(Name = "DirectionBar", GroupName = "Config", Order = 1)]
                public DirectionBar         ControlBar
                { get; set; }    
    
                [NinjaScriptProperty]
                [Display(Name = "ColorElipse", GroupName = "Config", Order = 2)]
                public       ColorElipse     colors
                { get; set; }    
        }
    flinging Error CS0246
    Any suggestions?

    thank you very much

    #2
    Hello franki,

    Thanks for your post.

    It looks like there is some additional code missing from your snippet for us to give specific insight. I have included an example which can demonstrate how you can create a enum that allows selection of a few different brushes. This is based on our TypeConverter example showing how to use a FriendlyEnumConverter.This converts the Enum to a string and then additional code can be used to convert the string values to a usable brush.

    SampleIndicatorTypeConverter - https://ninjatrader.com/support/help...r_to_custo.htm

    Please let me know if there is anything else we can do to help.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi ninjatrader_Jim
      You are right, I have not put much code because I put the code that I think is relevant, (as you can see in the image)
      The situation is to assign different colors to the ellipses, according to different parameter ranges.
      I have used enum for direction bar and I thought that "Brushes.colors" could already be configured internally like a enum, without the need for an indicator or initial clauses enum and to have the full range of colors without coding one by one in an indicator or previously enum
      I will investigate further FriendlyEnumConverter, it would be good to choose any available color, without putting one by one
      Once the strategy is complete in range parameters, it will be merged and adapted with UnmanagedTemplate created by you

      I am very grateful for the clarification and contribution of the indicator
      Thank you very much.

      Comment


        #4
        Originally posted by franki View Post
        Hi Ninjatrader team.

        I am trying to change the color of the ellipse from the script interface.
        I have another parameter under enum and it works correctly
        but it seems that "Brushes" does not support enum configuration manually.
        This is the closest I have come.

        Code:
        
        public enum DirectionBar
        {
        BarUP,
        BarDown,
        }
        
        
        
        namespace NinjaTrader.NinjaScript.Strategies
        {
        public class Example1 : Strategy
        {
        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        ("Default settings omitted for forum transcript")
        
        ControlBar = DirectionBar.BarUP;
        ColorElipse = Brushes.Green;
        }
        else if (State == State.Configure)
        {
        }
        }
        
        protected override void OnBarUpdate()
        {
        //Add your custom strategy logic here.
        
        if (ControlBar == DirectionBartolo.BarUP
        && Open[0] < Close[0])
        {
        Draw.Ellipse(this, "MyEllipseUP" + CurrentBar, 1, Low[0] -3 * TickSize, -1, High[0] +3* TickSize, ColorElipse);
        
        }
        }
        
        
        
        [NinjaScriptProperty]
        [Display(Name = "DirectionBar", GroupName = "Config", Order = 1)]
        public DirectionBar ControlBar
        { get; set; }
        
        [NinjaScriptProperty]
        [Display(Name = "ColorElipse", GroupName = "Config", Order = 2)]
        public ColorElipse colors
        { get; set; }
        }
        flinging Error CS0246
        Any suggestions?

        thank you very much
        You change the Brush. Essentially the Brush is the color. Where in NT7, we would say Color.Red, in NT8, we say Brushes.Red. etc

        Comment


          #5
          Originally posted by koganam View Post

          You change the Brush. Essentially the Brush is the color. Where in NT7, we would say Color.Red, in NT8, we say Brushes.Red. etc
          Thank you for your collaboration koganam
          I know how to do that.
          But I want to change the color of the ellipse from the script interface and have full access to the color palette, for example, just as if I define "MyOrderType" to access all the solutions from the script interface: "OrderType.Limit, Market, StoptLimit, StopMarket, MIT ", from the interface, without having to edit the strategy or access the code if I want change the type of order
          Best regards

          Comment


            #6
            Hello franki,

            Are you intending to add a Brush property to your script? Syntax can be generated for creating this sort of property by using a New Indicator Wizard (NinjaScript Editor > Indicators folder > Right Click > New Indicator) and creating a Brush property under Input parameters.

            Code:
            [NinjaScriptProperty]
            [XmlIgnore]
            [Display(Name="UserDefinedBrush", Order=1, GroupName="Parameters")]
            public Brush UserDefinedBrush
            { get; set; }
            
            [Browsable(false)]
            public string UserDefinedBrushSerializable
            {
                get { return Serialize.BrushToString(UserDefinedBrush); }
                set { UserDefinedBrush = Serialize.StringToBrush(value); }
            }
            I look forward to assisting.
            JimNinjaTrader Customer Service

            Comment


              #7
              Originally posted by franki View Post

              Thank you for your collaboration koganam
              I know how to do that.
              But I want to change the color of the ellipse from the script interface and have full access to the color palette, for example, just as if I define "MyOrderType" to access all the solutions from the script interface: "OrderType.Limit, Market, StoptLimit, StopMarket, MIT ", from the interface, without having to edit the strategy or access the code if I want change the type of order
              Best regards
              Then you want to make it a property. I presume you mean that you want to be able to modify the color from the PropertyGrid.

              Comment


                #8
                Originally posted by NinjaTrader_Jim View Post
                Hello franki,

                Are you intending to add a Brush property to your script? Syntax can be generated for creating this sort of property by using a New Indicator Wizard (NinjaScript Editor > Indicators folder > Right Click > New Indicator) and creating a Brush property under Input parameters.

                Code:
                [NinjaScriptProperty]
                [XmlIgnore]
                [Display(Name="UserDefinedBrush", Order=1, GroupName="Parameters")]
                public Brush UserDefinedBrush
                { get; set; }
                
                [Browsable(false)]
                public string UserDefinedBrushSerializable
                {
                get { return Serialize.BrushToString(UserDefinedBrush); }
                set { UserDefinedBrush = Serialize.StringToBrush(value); }
                }
                I look forward to assisting.
                Mr. Ninjatrader_Jim
                Exactly what I wanted was what you have given me.
                Instead of using an indicator, I have inserted the code into the strategy script itself.
                I am deeply satisfied with your work.
                You can see the result in the image.
                Thank you very much.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Irukandji, Yesterday, 02:53 AM
                2 responses
                17 views
                0 likes
                Last Post Irukandji  
                Started by adeelshahzad, Today, 03:54 AM
                0 responses
                3 views
                0 likes
                Last Post adeelshahzad  
                Started by CortexZenUSA, Today, 12:53 AM
                0 responses
                3 views
                0 likes
                Last Post CortexZenUSA  
                Started by CortexZenUSA, Today, 12:46 AM
                0 responses
                1 view
                0 likes
                Last Post CortexZenUSA  
                Started by usazencortex, Today, 12:43 AM
                0 responses
                5 views
                0 likes
                Last Post usazencortex  
                Working...
                X