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!
See more
See less

Partner 728x90

Collapse

Performance optimization

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • NinjaTrader_ChelseaB
    replied
    Hello NT Community,

    Here's another example with brushes that demonstrates how to add a set of brushes to a expandable / collapsible class 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)
    Attached Files
    Last edited by NinjaTrader_ChelseaB; 11-30-2017, 12:01 PM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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:


  • blar58
    replied
    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:


  • NinjaTrader_ChelseaB
    replied
    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.)
    Attached Files
    Last edited by NinjaTrader_ChelseaB; 06-07-2017, 07:26 AM.

    Leave a comment:


  • blar58
    replied
    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:


  • NinjaTrader_ChelseaB
    replied
    Hello blar58,

    May I confirm that you are reusing both sharpdx brushes and media brushes and that the sharpdx brushes are being created in OnRendrTargetChanged from the media brush?

    http://ninjatrader.com/support/helpG...getchanged.htm

    http://ninjatrader.com/support/forum...249#post461249

    Leave a comment:


  • blar58
    started a topic Performance optimization

    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 bit

Latest Posts

Collapse

Topics Statistics Last Post
Started by jhjhawkins, Today, 12:25 PM
0 responses
5 views
0 likes
Last Post jhjhawkins  
Started by rexsole, Today, 11:48 AM
1 response
13 views
0 likes
Last Post NinjaTrader_PatrickG  
Started by jeronymite, Yesterday, 05:05 PM
3 responses
54 views
0 likes
Last Post NinjaTrader_ChristopherJ  
Started by Don22Trader1, Yesterday, 05:54 PM
3 responses
49 views
0 likes
Last Post NinjaTrader_Jesse  
Started by Jebulay, Today, 08:36 AM
1 response
43 views
0 likes
Last Post NinjaTrader_PatrickG  
Working...
X