Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw.TextFixed problem

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

    Draw.TextFixed problem

    Hi all,

    on my indicator, inside OnStateChange() State.Configure, I have a line of code like that:

    Draw.TextFixed(this, "mytext1","Test Message", TextPosition.BottomRight, ChartControl.Properties.ChartText, ChartControl.Properties.LabelFont, Brushes.Transparent, Brushes.Transparent, 0);

    and that is working fine.
    The problem arise if I try to use that indicator as "Input Series" for another indicator (let's say for SMA...it doesn't make difference).
    The second indicator crashes with the following message:

    "Indicator 'fxMSTIndicator': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object."

    After some troubleshooting I found that the line of code that generate the problem is Draw.TextFixed...but in that line the only referenced object is this; how could "this" be an invalid reference?

    Thanks.

    #2
    Hello,

    Thank you for the question.

    In this case, you would need to move the logic to OnBarUpdate rather than OnStateChange. There is a note in the help guide regarding using drawing tools in OnStateChage: http://ninjatrader.com/support/helpG...us/drawing.htm

    Draw methods will not work if they are called from the OnStateChange() method. Although in your case, it seems to work in some cases and not others, it should still not be used in the OnStateChange method. Moving this to OnBarUpdate should prevent the errors when referencing the indicator.

    I look forward to being of further assistance.

    Comment


      #3
      He Jesse,

      moved to OnBarUpdate; unfortunately the problem remains:

      Indicator 'fxMSTIndicator': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.

      Thanks

      Comment


        #4
        Hello,

        Thank you for the reply.

        In this case, it is likely the ChartControl if you are not checking for null and the indicator is being referenced and not visualized it would be null.

        You could add a check like the following around the statement to prevent that.

        Code:
        if(ChartControl != null)
        {
        Draw.TextFixed(this, "mytext1","Test Message", TextPosition.BottomRight, ChartControl.Properties.ChartText, ChartControl.Properties.LabelFont, Brushes.Transparent, Brushes.Transparent, 0);
        }
        Please let me know if I may be of further assistance.

        Comment


          #5
          Hi Jesse,

          you were right; it works fine now.
          Thank you.

          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