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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse,

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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by terofs, Yesterday, 04:18 PM
          1 response
          21 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by CommonWhale, Today, 09:55 AM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by Gerik, Today, 09:40 AM
          2 responses
          7 views
          0 likes
          Last Post Gerik
          by Gerik
           
          Started by RookieTrader, Today, 09:37 AM
          2 responses
          12 views
          0 likes
          Last Post RookieTrader  
          Started by alifarahani, Today, 09:40 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X