Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Force Refresh() not working?

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

    Force Refresh() not working?

    I am using a custom rendering which draws a text character label to the right of plots, you see in the image. The text char is a variable. The character gets updated by a method called by OnbarUpdate and it corresponds to the color of the plot. I call the ForceRefresh() method after the change of the variable but the the custom rendering never changes the text label. The color of the plot corresponds to the label. As you can see the ForceRefresh() never makes the changes.

    Is there something I am missing?
    Click image for larger version

Name:	1.PNG
Views:	53
Size:	1.5 KB
ID:	1113162Click image for larger version

Name:	2.PNG
Views:	46
Size:	1.9 KB
ID:	1113163Click image for larger version

Name:	3.PNG
Views:	50
Size:	1.5 KB
ID:	1113164



    #2
    Hello cutzpr,

    The ForceRefresh method only queues a refresh but won't actually force anything. Are you certain that this is rendering related? For example when you see that this does not work correctly, can you resize the chart or click and drag the chart to see it update? If so that would indicate you do need to re render to have the change visible, if not that would indicate the problem is somewhere else.

    I look forward to being of further assistance.e
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      Yes it is rendering related. I resized the chart and moved the chart, minimized, maximized, and it never renders the new value. The character to the left (closest to the boxes) was drawn with Draw.Text inside OnBarUpdate and it work perfectly. The letter "Z" to the right was drawn using custom rendering using the same char variable. When Drawing the text using custom rendering it does not update. You can take a look at the highlighted image. I would rather not mix both custom rendering and the Draw.Text. Can you provide an example with custom rendering where the rendered text variable changes on OnBarUpdate but it renders correctly after ForceRefresh()

      Click image for larger version

Name:	1.PNG
Views:	43
Size:	4.2 KB
ID:	1113196Click image for larger version

Name:	2.PNG
Views:	31
Size:	8.4 KB
ID:	1113197Click image for larger version

Name:	3.PNG
Views:	41
Size:	3.7 KB
ID:	1113198

      Comment


        #4
        Code for reference
        Code:
            protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
            {
              // call the base.OnRender() to ensure standard Plots work as designed
              base.OnRender(chartControl, chartScale);
        
             ChartControlProperties chartProperties = chartControl.Properties;    
                //--Setup panel
                if(chartScale.Properties.YAxisScalingType != YAxisScalingType.Linear)
                    chartScale.Properties.YAxisScalingType = YAxisScalingType.Linear;
                if(chartScale.Properties.YAxisRangeType != YAxisRangeType.Fixed)
                    chartScale.Properties.YAxisRangeType = YAxisRangeType.Fixed;
                if(chartScale.Properties.FixedScaleMax != 7)
                    chartScale.Properties.FixedScaleMax = 7;
                if(chartScale.Properties.FixedScaleMin != 0)
                    chartScale.Properties.FixedScaleMin = 0;
                //--
        
                    if(!IsInHitTest) // Text Labels
                    {
                    NinjaTrader.Gui.Tools.SimpleFont simpleFont1= new NinjaTrader.Gui.Tools.SimpleFont("Verdana", 10) { Bold = false };
                    NinjaTrader.Gui.Tools.SimpleFont simpleFont2= new NinjaTrader.Gui.Tools.SimpleFont("Verdana", 10) { Bold = false };
                    float demi1YPoint;
                    float demi2YPoint;
                    float demi3YPoint; 
                    float demi4YPoint;
        
                    padX = 20;
                    padY = 6;
                    endBarX = chartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex) + padX ; // Same X Coordinate for all text labels, only Y coordinate changes
        
                    //--Base Period - Inverted label
        
                    SharpDX.Direct2D1.SolidColorBrush textBrushDx = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget,SharpDX.Color.Black);            
                    SharpDX.DirectWrite.TextFormat textFormat1 = simpleFont1.ToDirectWriteTextFormat();
                    SharpDX.DirectWrite.TextLayout textLayoutInvert;        
        
                    textLayoutInvert = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory,label1, textFormat1, ChartPanel.X + ChartPanel.W,
                            textFormat1.FontSize);
        
                    SharpDX.Vector2 lowerTextPoint = new SharpDX.Vector2(ChartPanel.W - textLayoutInvert.Metrics.Width, ChartPanel.Y + (ChartPanel.H - textLayoutInvert.Metrics.Height));
                    //SharpDX.Vector2 lowerTextPoint = new SharpDX.Vector2(endBarX - textLayoutInvert.Metrics.Width , ChartPanel.Y + (ChartPanel.H - textLayoutInvert.Metrics.Height));
                    RenderTarget.DrawTextLayout(lowerTextPoint, textLayoutInvert, textBrushDx, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
        
        
                    //--demi Labels            
                    SharpDX.DirectWrite.TextFormat textFormat2 = simpleFont2.ToDirectWriteTextFormat();        
        
                    //demi1            
                    SharpDX.DirectWrite.TextLayout textLayout1 = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory,demi1trendchar[0] + " " + demi1Label, textFormat2, ChartPanel.X + ChartPanel.W,
                    textFormat2.FontSize);
                    demi1YPoint = chartScale.GetYByValue(5) - textLayout1.Metrics.Height;
                    SharpDX.Vector2 demi1TextPoint = new SharpDX.Vector2(endBarX, demi1YPoint + padY);
        
                    //demi2
                    SharpDX.DirectWrite.TextLayout textLayout2 = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory,demi2trendchar[0] + " " + demi2Label, textFormat2, ChartPanel.X + ChartPanel.W,
                    textFormat2.FontSize);
                    demi2YPoint = chartScale.GetYByValue(4) - textLayout2.Metrics.Height;
                    SharpDX.Vector2 demi2TextPoint = new SharpDX.Vector2(endBarX, demi2YPoint + padY);
        
                    //demi3
                    SharpDX.DirectWrite.TextLayout textLayout3 = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory, demi3trendchar[0] + " " + demi3Label, textFormat2, ChartPanel.X + ChartPanel.W,
                    textFormat2.FontSize);
                    demi3YPoint = chartScale.GetYByValue(3) - textLayout3.Metrics.Height;
                    SharpDX.Vector2 demi3TextPoint = new SharpDX.Vector2(endBarX, demi3YPoint + padY);
        
                    //demi4
                    SharpDX.DirectWrite.TextLayout textLayout4 = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory,demi4trendchar[0] + " " + demi4Label, textFormat2, ChartPanel.X + ChartPanel.W,
                    textFormat2.FontSize);
                    demi4YPoint = chartScale.GetYByValue(2) - textLayout4.Metrics.Height;
                    SharpDX.Vector2 demi4TextPoint = new SharpDX.Vector2(endBarX, demi4YPoint + padY);
        
        
                    RenderTarget.DrawTextLayout(demi1TextPoint, textLayout1, textBrushDx, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
                    RenderTarget.DrawTextLayout(demi2TextPoint, textLayout2, textBrushDx, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
                    RenderTarget.DrawTextLayout(demi3TextPoint, textLayout3, textBrushDx, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
                    RenderTarget.DrawTextLayout(demi4TextPoint, textLayout4, textBrushDx, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
        
                    textLayoutInvert.Dispose();
                    textBrushDx.Dispose();
                    textLayout1.Dispose();
                    textLayout2.Dispose();
                    textLayout3.Dispose();
                    textLayout4.Dispose();
        
                    //Custom Lines
        
                    }

        Comment


          #5
          Hello cutzpr,

          Thanks for checking that and confirming its related to the render pass.

          There is technically no way to force a render besides causing an event which needs a render such as resizing or clicking. One item you can try is drawing a drawing object and immediately removing it. Removing an object forces a render so that technically should update the chart. This was a workaround found during beta so I am unsure if that still works today but is something you can quickly try.

          Code:
          Draw.Dot(this, "renderdummy", false, 0, 0, Brushes.Transparent);
          RemoveDrawObject("renderdummy");
          This would not be something you would want to do on every render pass but only in the situation where it does not render. I am not certain if that is caused by a specific situation such as no data or when it finished loading but this would be the final step and called one time to finish the render. It should only be called when a render is needed to be forced but otherwise would cause a large performance impact if you call it all the time.


          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Thank you Jesse for the suggestion. I tried calling ForceRefresh with creating and deleting the dummy dot and it did not work. I guess I will have to use Draw.Text which is currently working and refreshing.

            Comment


              #7
              I know that I'm late but what about...?

              ChartPanel.InvalidateVisual();
              ForceRefresh();

              Comment


                #8
                Hello ntdev,

                I just wanted to provide a quick comment about Invalidate, It is never suggested to use InvalidateVisual as it can lead to deadlocks. This is documented in the ForceRefresh documentation.



                I look forward to being of further assistance.

                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ArmKnuckle, Today, 10:02 PM
                0 responses
                5 views
                0 likes
                Last Post ArmKnuckle  
                Started by jeronymite, Today, 08:29 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_EricB  
                Started by soon123, Today, 07:38 PM
                2 responses
                9 views
                0 likes
                Last Post soon123
                by soon123
                 
                Started by ser1es, Today, 04:26 PM
                1 response
                18 views
                0 likes
                Last Post NinjaTrader_ShawnB  
                Started by ErikY, Today, 02:14 PM
                1 response
                15 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Working...
                X