Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

onrender optimization

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

    onrender optimization

    Looking at ChartStyles is seems to me that code is initializing variables on every visible candle. For example:

    PHP Code:
                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));&#8203; 
    
    I am curious for the reason why historical, visible candle values cached?
    Last edited by MiCe1999; 05-08-2025, 11:05 AM.

    #2
    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

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      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.
      Sorry, my question was missing 'are not' cached. As you point out on each candle the variables are cached before drawing.

      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


        #4
        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


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          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.
          https://support.ninjatrader.com/s/feature-request
          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.

          Click image for larger version

Name:	image.png
Views:	279
Size:	3.2 KB
ID:	1342869

          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


            #6
            Hello MiCe1999,

            A geometry sink uses a lot memory resources, and would be suited to a single rendered object, not several.
            Chelsea B.NinjaTrader Customer Service

            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 Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            323 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            99 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            543 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            545 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X