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 GLFX005, Today, 03:23 AM
          0 responses
          1 view
          0 likes
          Last Post GLFX005
          by GLFX005
           
          Started by XXtrader, Yesterday, 11:30 PM
          2 responses
          11 views
          0 likes
          Last Post XXtrader  
          Started by Waxavi, Today, 02:10 AM
          0 responses
          6 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          14 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          3 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Working...
          X