#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
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!
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
NinjaTrader
I can't get the transparency to change when it's a user input
Collapse
X
-
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:Last edited by alanlopen; 03-23-2023, 05:09 AM.Tags: None
-
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
-
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
-
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 ninza33, Today, 06:46 PM
|
0 responses
1 view
0 likes
|
Last Post
by ninza33
Today, 06:46 PM
|
||
Started by sandman, Today, 06:31 PM
|
0 responses
3 views
0 likes
|
Last Post
by sandman
Today, 06:31 PM
|
||
Started by martini, 03-27-2024, 04:45 PM
|
6 responses
43 views
0 likes
|
Last Post Today, 05:33 PM | ||
Started by bsbisme, Today, 05:06 PM
|
0 responses
5 views
0 likes
|
Last Post
by bsbisme
Today, 05:06 PM
|
||
Started by kezyclaire, 12-01-2023, 09:37 AM
|
4 responses
157 views
0 likes
|
Last Post Today, 04:29 PM |
Comment