Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnRenderTargetChanged() returns null value

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

    OnRenderTargetChanged() returns null value

    Hi,
    I have simply copied and pasted the codes from NT8 help guide for testing like below, but it returns null exception for OnRenderTargetChanged(). Can you advise?
    Code:
    private SharpDX.Direct2D1.Brush dxBrush = null; // the SharpDX brush used for rendering      
    private System.Windows.Media.SolidColorBrush brush Color; // used to determine the color of the brush conditionally
    
    protected override void OnStateChange()
    {
      if (State == State.SetDefaults)
      {
        Name = "OnRenderTargetChanged Example";
        IsOverlay = false;
      }
    }
    
    protected override void OnBarUpdate()
    {
      if (Close[0] > Open[0])
      {
        brushColor = Brushes.Green;
      }
    
      else if (Close[0] < Open[0])
      {
        brushColor = Brushes.Red;
      }
    
      else brushColor = Brushes.Blue;
    }
    
    public override void OnRenderTargetChanged()
    {
      // if dxBrush exists on first render target change, dispose of it
      if (dxBrush != null)
      {
        dxBrush.Dispose();
      }
    
      // recalculate dxBrush from value calculated in OnBarUpdated when RenderTarget is recreated
      if (RenderTarget != null)
        dxBrush = brushColor.ToDxBrush(RenderTarget);
    }
    
    protected override void OnRender(ChartControl char tControl, ChartScale chartScale)
    {
      // fill a custom SharpDX rectangle using the dx brush
      RenderTarget.FillRectangle(new SharpDX.Rectangle F(ChartPanel.X, ChartPanel.Y, ChartPanel.W, ChartP anel.H), dxBrush);
    }

    #2
    Hello asmmbillah,

    Thanks for your post.

    It seems that the brushColor variable is returning a null value when applying the script to a chart. You could resolve this error message by setting brushColor to an initial value in State.SetDefaults. For example, see below.

    Code:
    private SharpDX.Direct2D1.Brush dxBrush = null; // the SharpDX brush used for rendering
    private System.Windows.Media.SolidColorBrush brushColor; // used to determine the color of the brush conditionally
    
    protected override void OnStateChange()
    {
      if (State == State.SetDefaults)
      { 
        Name = "OnRenderTargetChanged Example";
        IsOverlay = false;
        brushColor = Brushes.Blue;
      }
    }
    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      thanks for that. But I can see, it does not change the color of the render based on the logics within onbarupdate. Can you please check and advise?

      Comment


        #4
        Hello asmmbillah,

        Thanks for your note.

        Upon initially adding the OnRenderTargetChanged example script to a chart, a blue rectangle will appear. Then, the next time the RenderTarget is recreated, the rectangle color will reflect the brush color set in OnBarUpdate(). Note that the color of the rectangle will only change colors once a RenderTarget is recreated.

        See this demonstration video to see the OnRenderTargetChanged example in action: https://brandonh-ninjatrader.tinytak...Nl8xNzM4MzkxOQ

        I have also attached the OnRenderTargetChanged script that I am testing with.

        Let us know if we may assist further.
        Attached Files
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          thanks, I missed pressing the click.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          635 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          365 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          106 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          567 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          571 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X