Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Brush Input Ambiguous reference Error
Collapse
X
-
Hello,
Thank you for the post.
This is likely due to the using statements in the script where this syntax is being copied. Both SharpDX and Windows have brush defined as a type.
If you are trying to use a System.Windows.Media.Brush like the sample, you would need to add:
to the top of the file with the other using statements. But this will still conflict if you use both SharpDX and System.Windows.Media.Code:using System.Windows.Media;
If you use both SharpDX brushes and 'System.Windows.Media.Brush, you would need to be explicit when you use them in your code. for example:
orCode:System.Windows.Media.Brush myBrush = System.Windows.Media.Brushes.Red;
Code:SharpDX.Direct2D1.Brush myBrush;
I look forward to being of further assistance.
- Likes 1
Comment
-
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; using SharpDX; using SharpDX.Direct2D1; #endregion //This namespace holds Indicators in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Indicators { public class _OnRenderPlot : Indicator { private int cBar; private double cHigh; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "_OnRenderPlot"; Calculate = Calculate.OnEachTick; IsOverlay = true; 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; MaximumBarsLookBack = MaximumBarsLookBack.Infinite; ShowTransparentPlotsInDataBox = true; plot1Brush = Brushes.ForestGreen; // Adds a Cyan Dash-Line style plot with 5pixel width and 3% opacity to hide the plot AddPlot(new Stroke(Brushes.Transparent, DashStyleHelper.Dash, 5, 3), PlotStyle.Hash, "MyPlot1"); } else if (State == State.Configure) { } } protected override void OnBarUpdate() { if (CurrentBar <21) return; if (Open[0] < Close[0]) { cBar = CurrentBar; cHigh = High[0]; MyPlot1[0] = cHigh; } if ((CurrentBar - cBar) < 4) { MyPlot1[0] = cHigh; } } protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { base.OnRender(chartControl, chartScale); SharpDX.Direct2D1.Brush plot1BrushDx; plot1BrushDx = plot1Brush.ToDxBrush(RenderTarget); SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode; RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; Vector2 point0 = new Vector2(); Vector2 point1 = new Vector2(); Vector2 point2 = new Vector2(); Vector2 point3 = new Vector2(); for (int barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++) { double plotValue0 = 0, plotValue1 = 0; float valY0, xHeight0, x0, barWidth0, xWidth0, valY1, xHeight1, x1, barWidth1, xWidth1, outlineWidth; plotValue0 = MyPlot1.GetValueAt(barIndex); valY0 = chartScale.GetYByValue(plotValue0); x0 = chartControl.GetXByBarIndex(ChartBars, barIndex); barWidth0 = (float)chartControl.BarWidth; outlineWidth = ChartBars.Properties.ChartStyle.Stroke2.Width; // 1.0f; point0.X = x0 - barWidth0 - outlineWidth; point0.Y = valY0; point1.X = x0 + barWidth0 + outlineWidth; point1.Y = valY0; xHeight0 = 10.0f; xWidth0 = (point1.X - point0.X); bool Cond0 = ( plotValue1 != double.NaN && plotValue0 != double.NaN && ( plotValue1 != plotValue0 ) || (plotValue1 == plotValue0 )); if ( Cond0 ) { RenderTarget.DrawLine(point0, point1, plot1BrushDx, 4); } plotValue1 = MyPlot1.GetValueAt(barIndex-1); valY1 = chartScale.GetYByValue(plotValue1); x1 = chartControl.GetXByBarIndex(ChartBars, barIndex-1); point2.X = x1 + barWidth0 - outlineWidth; point2.Y = valY1; point3.X = x0 - barWidth0 + outlineWidth; point3.Y = valY1; xHeight1 = 10.0f; xWidth1 = (point3.X - point2.X); bool Cond1 = ( plotValue1 != double.NaN && plotValue0 != double.NaN && plotValue1 == plotValue0 && !( plotValue1 != plotValue0 )); if ( Cond1 ) { RenderTarget.DrawLine(point2, point3, plot1BrushDx, 4); } } RenderTarget.AntialiasMode = oldAntialiasMode; } #region Properties [Browsable(false)] [XmlIgnore] public Series<double> MyPlot1 { get { return Values[0]; } } [NinjaScriptProperty] [XmlIgnore] [Display(Name="Plot Brush", Order=1, GroupName="Parameters")] public System.Windows.Media.Brush plot1Brush { get; set; } [Browsable(false)] public string plot1BrushSerializable { get { return Serialize.BrushToString(plot1Brush); } set { plot1Brush = Serialize.StringToBrush(value); } } #endregion } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private _OnRenderPlot[] cache_OnRenderPlot; public _OnRenderPlot _OnRenderPlot(System.Windows.Media.Brush plot1Brush) { return _OnRenderPlot(Input, plot1Brush); } public _OnRenderPlot _OnRenderPlot(ISeries<double> input, System.Windows.Media.Brush plot1Brush) { if (cache_OnRenderPlot != null) for (int idx = 0; idx < cache_OnRenderPlot.Length; idx++) if (cache_OnRenderPlot[idx] != null && cache_OnRenderPlot[idx].plot1Brush == plot1Brush && cache_OnRenderPlot[idx].EqualsInput(input)) return cache_OnRenderPlot[idx]; return CacheIndicator<_OnRenderPlot>(new _OnRenderPlot(){ plot1Brush = plot1Brush }, input, ref cache_OnRenderPlot); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators._OnRenderPlot _OnRenderPlot(System.Windows.Media.Brush plot1Brush) { return indicator._OnRenderPlot(Input, plot1Brush); } public Indicators._OnRenderPlot _OnRenderPlot(ISeries<double> input , System.Windows.Media.Brush plot1Brush) { return indicator._OnRenderPlot(input, plot1Brush); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators._OnRenderPlot _OnRenderPlot(System.Windows.Media.Brush plot1Brush) { return indicator._OnRenderPlot(Input, plot1Brush); } public Indicators._OnRenderPlot _OnRenderPlot(ISeries<double> input , System.Windows.Media.Brush plot1Brush) { return indicator._OnRenderPlot(input, plot1Brush); } } } #endregionLast edited by PaulMohn; 08-17-2024, 08:23 AM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
587 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
341 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 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
555 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