Thank you
FVJ
// 1.4 - Rendering Custom Shapes
// SharpDX namespace consists of several shapes you can use to draw objects more complicated than lines
// For example, we can use the RectangleF object to draw a rectangle that covers the entire chart area
SharpDX.RectangleF rect = new SharpDX.RectangleF(startPoint.X, startPoint.Y, width, height);
// The RenderTarget consists of two commands related to Rectangles.
// The FillRectangle() method is used to "Paint" the area of a Rectangle
RenderTarget.FillRectangle(rect, areaBrushDx);
// and DrawRectangle() is used to "Paint" the outline of a Rectangle
RenderTarget.DrawRectangle(rect, customDXBrush, 2);
// Another example is an ellipse which can be used to draw circles
// The ellipse center point can be used from the Vectors calculated earlier
// The width and height an absolute 100 device pixels
// To ensure that pixel coordinates work across all DPI devices, we use the NinjaTrader ChartingExteions methods
// Which will convert the "100" value from WPF pixels to Device Pixels both vertically and horizontally
int ellipseRadiusY = ChartingExtensions.ConvertToVerticalPixels(100, ChartControl.PresentationSource);
int ellipseRadiusX = ChartingExtensions.ConvertToHorizontalPixels(100, ChartControl.PresentationSource);
SharpDX.Direct2D1.Ellipse ellipse = new SharpDX.Direct2D1.Ellipse(center, ellipseRadiusX, ellipseRadiusY);
// 1.5 - Complex Brush Types and Shapes
// For this ellipse, we can use one of the more complex brush types "RadialGradientBrush"
// Warning: RadialGradientBrush objects must be disposed of after they have been used
SharpDX.Direct2D1.RadialGradientBrush radialGradientBrush;
// However creating a RadialGradientBrush requires a few more properties than SolidColorBrush
// First, you need to define the array gradient stops the brush will eventually use
SharpDX.Direct2D1.GradientStop[] gradientStops = new SharpDX.Direct2D1.GradientStop[2];
// With the gradientStops array, we can describe the color and position of the individual gradients
gradientStops[0].Color = SharpDX.Color.Goldenrod;
gradientStops[0].Position = 0.0f;
gradientStops[1].Color = SharpDX.Color.SeaGreen;
gradientStops[1].Position = 1.0f;
// then declare a GradientStopCollection from our render target that uses the gradientStops array defined just before
// Warning: GradientStopCollection objects must be disposed of after they have been used
SharpDX.Direct2D1.GradientStopCollection gradientStopCollection =
new SharpDX.Direct2D1.GradientStopCollection(RenderTarget, gradientStops);
// we also need to tell our RadialGradientBrush to match the size and shape of the ellipse that we will be drawing
// for convenience, SharpDX provides a RadialGradientBrushProperties structure to help define these properties
SharpDX.Direct2D1.RadialGradientBrushProperties radialGradientBrushProperties =
new SharpDX.Direct2D1.RadialGradientBrushProperties
{
GradientOriginOffset = new SharpDX.Vector2(0, 0),
Center = ellipse.Point,
RadiusX = ellipse.RadiusY,
RadiusY = ellipse.RadiusY
};
// we now have everything we need to create a radial gradient brush
radialGradientBrush = new SharpDX.Direct2D1.RadialGradientBrush(RenderTarget, radialGradientBrushProperties,
gradientStopCollection);
// Finally, we can use this radialGradientBrush to "Paint" the area of the ellipse
RenderTarget.FillEllipse(ellipse, radialGradientBrush);
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
int rightMostBar = ChartBars.ToIndex; //Note:First bar on chart is 0
int leftMostBar = ChartBars.FromIndex; //Note:First bar on chart is 0
SharpDX.Direct2D1.SolidColorBrush solidColorBrush;
for (int i=leftMostBar; i <= rightMostBar; i++) //Start at necessary List position
{
float currentX = chartControl.GetXByBarIndex(ChartBars, i);
int ellipseRadiusY = chartControl.GetBarPaintWidth(chartControl.BarsArray[0]);
int ellipseRadiusX = chartControl.GetBarPaintWidth(chartControl.BarsArray[0]);
//--------------------------
if(myStateUp.GetValueAt(i) == +1)
{
SharpDX.Vector2 center = new SharpDX.Vector2(currentX, ChartPanel.Y + (ChartPanel.H) -vOffset-7);
SharpDX.Direct2D1.Ellipse ellipse = new SharpDX.Direct2D1.Ellipse(center, ellipseRadiusX, ellipseRadiusY);
solidColorBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.LightBlue);
RenderTarget.FillEllipse(ellipse, solidColorBrush);
solidColorBrush.Dispose();
}
if(myStateUp.GetValueAt(i) == -1 )
{
SharpDX.Vector2 center = new SharpDX.Vector2(currentX, ChartPanel.Y + (ChartPanel.H)-vOffset -0);
SharpDX.Direct2D1.Ellipse ellipse = new SharpDX.Direct2D1.Ellipse(center, ellipseRadiusX, ellipseRadiusY);
solidColorBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Red);
RenderTarget.FillEllipse(ellipse, solidColorBrush);
solidColorBrush.Dispose();
}
}
//Allow onRender+
base.OnRender(chartControl, chartScale);
}
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
599 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
344 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
558 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
557 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|
Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing one’s financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.
CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.
This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates.
Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.

Comment