#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
No announcement yet.
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;
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
580 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
335 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
102 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
554 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
552 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment