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

I can't get the transparency to change when it's a user input

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

    I can't get the transparency to change when it's a user input

    I want the user to choose the transparency of the color of the plot, so I use a public proeprty for this. But no matter what I enter after the indicator is loaded on the chart, the transparency doesn't change. Once it is loaded, I open the settings and I can change the color without problem, for instance choosing ''DeepPink'', but the transparency never changes no matter the input.


    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class MyCustomIndicator : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "MyCustomIndicator";
                    Calculate                                    = Calculate.OnPriceChange;
                    IsOverlay                                    = false;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
    Transparency_temp_color=11;
    temp_color=new SolidColorBrush(Color.FromArgb(Transparency_temp_color, 233, 122, 44));
    temp_color.Freeze();
                }
                else if (State == State.Configure)
                {
                    AddPlot(temp_color, "PrintClose");
                }
            }
    
            protected override void OnBarUpdate()
            {
                //Add your custom indicator logic here.
                Value[0]=Close[0];
            }
    
            #region Properties
    
    
    
    //Create our user definable color input
                         [XmlIgnore()]
                         [Display(Name="temp_color", Description="abcd__temp_color", Order=16, GroupName="AAA")]
     public Brush temp_color
     {get; set;}
    
    //Serialize our Color object
                         [Browsable(false)]
     public string temp_colorSerialize
     {
      get{return Serialize.BrushToString(temp_color);}
      set{temp_color=Serialize.StringToBrush(value);}
     }
    
     [NinjaScriptProperty]
                         [Display(Name="Transparency_temp_color", Description="abcd_Transparency_temp_color", Order=17, GroupName="AAA")]
     public byte Transparency_temp_color
     {get; set;}
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> PrintClose
            {
                get { return Values[0]; }
            }
            #endregion
    
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private MyCustomIndicator[] cacheMyCustomIndicator;
            public MyCustomIndicator MyCustomIndicator(byte transparency_temp_color)
            {
                return MyCustomIndicator(Input, transparency_temp_color);
            }
    
            public MyCustomIndicator MyCustomIndicator(ISeries<double> input, byte transparency_temp_color)
            {
                if (cacheMyCustomIndicator != null)
                    for (int idx = 0; idx < cacheMyCustomIndicator.Length; idx++)
                        if (cacheMyCustomIndicator[idx] != null && cacheMyCustomIndicator[idx].Transparency_temp_color == transparency_temp_color && cacheMyCustomIndicator[idx].EqualsInput(input))
                            return cacheMyCustomIndicator[idx];
                return CacheIndicator<MyCustomIndicator>(new MyCustomIndicator(){ Transparency_temp_color = transparency_temp_color }, input, ref cacheMyCustomIndicator);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.MyCustomIndicator MyCustomIndicator(byte transparency_temp_color)
            {
                return indicator.MyCustomIndicator(Input, transparency_temp_color);
            }
    
            public Indicators.MyCustomIndicator MyCustomIndicator(ISeries<double> input , byte transparency_temp_color)
            {
                return indicator.MyCustomIndicator(input, transparency_temp_color);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.MyCustomIndicator MyCustomIndicator(byte transparency_temp_color)
            {
                return indicator.MyCustomIndicator(Input, transparency_temp_color);
            }
    
            public Indicators.MyCustomIndicator MyCustomIndicator(ISeries<double> input , byte transparency_temp_color)
            {
                return indicator.MyCustomIndicator(input, transparency_temp_color);
            }
        }
    }
    
    #endregion
    ​
    Last edited by alanlopen; 03-23-2023, 05:09 AM.

    #2
    In State.Configure you can make a copy of that input parameter brush that has the altered transparency, freeze it, and keep it in a local variable for later use in OnBarUpdate or OnRender.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      I dont'understand fully what your idea is.

      I don't know how to turn a brush defined, in if (State == State.SetDefaults), wtih FromRgb(), ie temp_color=new SolidColorBrush(Color.FromRgb(233, 122, 44)); into a brush with transpraency.

      The official doc by MSDN says there is a function FromArgb(Int32, Color)​, but the Ninja compiler says FromArgb() doesnt take 2 arguments....

      Comment


        #4
        Hello alanlopen,

        State.SetDefaults is used to provide a default value before the user selects anything. You would need to do your transpancey change and Freeze() in a later state like State.Configure. You also don't want to reset the User Input, you need to make a private variable with a different name and assign the brush with transparency to that, then use that private variable in your code.

        The easiest way to do this would be to make two user inputs, one for a brush and one for a double for opacity. Then you can do like the following to clone the brush and freeze it:

        Code:
        private Brush finalBrush = Brushes.Blue;
        
        // in State.Configure
        
        Brush brushCopy = temp_color.Clone();
        brushCopy.Opacity = opacity / 100d;
        brushCopy.Freeze();
        finalBrush = brushCopy;
        JesseNinjaTrader Customer Service

        Comment


          #5
          what is the 100d you use ?

          Comment


            #6
            Hello alanlopen,

            when you see d at the end of a number that specifies is a double, if you do math with an integer you would get a integer results. Opacity is a double number between 0-1 so dividing the users percentage of say 50 would result in 0.5 by diving it by 100.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,603 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            8 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            4 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            12 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X