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
Performance optimization
Collapse
X
-
Hello NT Community,
Here's another example with brushes that demonstrates how to add a set of brushes to a expandable / collapsible class (using the ExpandableObjectConverter typeconverter) so these are grouped together in the properties window.
(edited Nov 30, 2017 to correct a public variable that should have been a private variable which causes issues with saving an indicator preset)Last edited by NinjaTrader_ChelseaB; 11-30-2017, 01:01 PM.
-
Hello blar58,
If you are changing the AntialiasMode, then yes, you should change this back.
If you choose not to change the AntialiasMode, then no, no need to track the original mode and change it back.
With the AntialiasMode set to Alias, the rendering is jagged, with AntialiasMode set to PerPrimitive the rendering is smooth.
Leave a comment:
-
Thank you Chelsea
I think I will solve my perfromance problem.
Quick question :
Looking at the code you sent me what do these two lines from OnRender means :
previousAntialiasMode = RenderTarget.AntialiasMode;
RenderTarget.AntialiasMode = previousAntialiasMode;
Should I use that in my code
Thanks
Leave a comment:
-
Hello blar58,
I would recommend creating/recreating the sharpdx brushes in OnRenderTargetChanged() so that these do not collect in memory.
This can be done with a loop over a dictionary in OnRenderTargetChanged().
Attached is an example that demonstrates.
(edit, I've made some small changes to the script, but none that change what I am demonstrating)
(second edit, since I'm posting how to do this with a dictionary here, I'm adding the example I've made without using a dictionary as well for convenience and to compare with.)Last edited by NinjaTrader_ChelseaB; 06-07-2017, 08:26 AM.
- Likes 1
Leave a comment:
-
Hi Chelsea
Yes I am reusing sharpdx and media brushes
No brushdx are created on a method that is being called from OnRender.
I have no choice because I know only the brushes when I loop through the dictionary which is being called from OnRender.
The brushdx is disposed from OnRenderTargetChanged though.
Leave a comment:
-
Performance optimization
Hi,
I just want to make sure that my code is optimize for best performance.
I am painting lots of numbers and letters to the chart window through a loop and these objects are using different brushes.
I notice that sometimes it slows performance when I move the chart with my mouse.
Here is the structure of my code
I have all objects to be painted in a SortedDictionary and it is part of the drawing method which is called from OnRender :
foreach(KeyValuePair<int, List<string> k in dic)
{
List<string> list = k.Value as List<string>();
for(int i=0; i<list.Count; i++)
{
curElement = list[i];
// do stuff
if(xxxx)
brushColor = Brushes.Yellow
else
brushColor = Brushes.Red;
brushColorDx = brushColor.ToDxBrush(RenderTarget);
RenderTargert.DrawText(xxxxxxxxx, brushColorDx);
}
}
And OnRenderTargetChanged I have :
if(brushColorDx != null)
brushColorDx.Dispose();
I am just wondering if I manage the brushDx the right way for performance optimization.
It seems that more and more painting (shrinking the chart as much as I can ) )slows down the indicator a bitTags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by wzgy0920, 04-20-2024, 06:09 PM
|
2 responses
26 views
0 likes
|
Last Post
by wzgy0920
Today, 10:43 PM
|
||
Started by wzgy0920, 02-22-2024, 01:11 AM
|
5 responses
32 views
0 likes
|
Last Post
by wzgy0920
Today, 10:33 PM
|
||
Started by wzgy0920, Yesterday, 09:53 PM
|
2 responses
49 views
0 likes
|
Last Post
by wzgy0920
Today, 10:29 PM
|
||
Started by Kensonprib, 04-28-2021, 10:11 AM
|
5 responses
191 views
0 likes
|
Last Post
by Hasadafa
Today, 10:19 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
11 responses
3,230 views
0 likes
|
Last Post Today, 08:07 PM |
Leave a comment: