for (int idx = chartBars.FromIndex; idx <= chartBars.ToIndex; idx++)
{
SharpDX.Direct2D1.Brush overriddenBrush = chartControl.GetBarOverrideBrush(chartBars, idx);
double closeValue = bars.GetClose(idx);
float close = chartScale.GetYByValue(closeValue);
float high = chartScale.GetYByValue(bars.GetHigh(idx));
float low = chartScale.GetYByValue(bars.GetLow(idx));
double openValue = bars.GetOpen(idx);
float open = chartScale.GetYByValue(openValue);
float x = chartControl.GetXByBarIndex(chartBars, idx);
point0.X = point1.X = x;
point0.Y = high - lineWidth * 0.5f;
point1.Y = low + lineWidth * 0.5f;
SharpDX.Direct2D1.Brush b = overriddenBrush ?? (closeValue >= openValue ? UpBrushDX : DownBrushDX);
if (!(b is SharpDX.Direct2D1.SolidColorBrush))
TransformBrush(b, new RectangleF(point0.X - lineWidth * 1.5f, point0.Y, lineWidth * 3, point1.Y - point0.Y));​
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
onrender optimization
Collapse
X
-
onrender optimization
Looking at ChartStyles is seems to me that code is initializing variables on every visible candle. For example:
I am curious for the reason why historical, visible candle values cached?PHP Code:Last edited by MiCe1999; 05-08-2025, 11:05 AM.Tags: None
-
Hello MiCe1999,
Data types like double and float aren't generally resource intensive the way a class object or brush is.
While it can be beneficial to use class level variables and update the values in memory, the cost here is not impactful.
The point and brush objects however, are impactful and do appear to be class level in this code sample you have provided.Chelsea B.NinjaTrader Customer Service
-
Sorry, my question was missing 'are not' cached. As you point out on each candle the variables are cached before drawing.Originally posted by NinjaTrader_ChelseaB View PostHello MiCe1999,
Data types like double and float aren't generally resource intensive the way a class object or brush is.
While it can be beneficial to use class level variables and update the values in memory, the cost here is not impactful.
The point and brush objects however, are impactful and do appear to be class level in this code sample you have provided.
Basically, what I'm asking is why not use additional data structure, like a sliding window, and cache x/y/brush values for each visible candle (except CurrentBar).Last edited by MiCe1999; 05-08-2025, 11:12 AM.
Comment
-
Hello MiCe1999,
The chart time scale and price scale can move. This means that the x and y values need to be converted from price on each render pass as both the x and y values will change for any given price as the chart moves.
If you have created your own chart style script with a large efficiency gain you can submit the code in a feature request for the development team to consider.
Chelsea B.NinjaTrader Customer Service
Comment
-
Thanks, I'm not a programmer, I am asking primarily to widen my knowledge and understand design decisions, not to criticize.Based on my testing, even caching intrabar saves about 25% (with 1500 candles visible) so there seems to be some merit to caching when there are a lot of candles on the screen. I think with further optimizations this could be lowered further, maybe by another 75% when scaling does not change which may be helpful in fast markets.Originally posted by NinjaTrader_ChelseaB View PostHello MiCe1999,
The chart time scale and price scale can move. This means that the x and y values need to be converted from price on each render pass as both the x and y values will change for any given price as the chart moves.
If you have created your own chart style script with a large efficiency gain you can submit the code in a feature request for the development team to consider.
https://support.ninjatrader.com/s/feature-request
Question: AI was recommending using GeometrySink to dramatically lower the number of drawing calls: do you think that makes sense for NT8/ChartStyle in practice? Is it worth pursuing?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
547 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
323 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
99 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
543 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
545 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment