Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object reference not set to an instance of an object

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

    Object reference not set to an instance of an object

    Hello

    Debugging my indicator there is an error that occurs randomly and always when I try to get y-cordinate to draw OnRender method

    float yStartLong = chartScale.GetYByValue(Low.GetValueAt(barIndex) - ticksDistance * TickSize);

    I have read many topics about this in forum, but I don't know what I have to check for null and more important yet, why this error appears in one bar and not in others.

    How can I fix this?

    Sincerely,
    Attached Files

    #2
    Hi Impeesa, thanks for writing in.

    The TriggerCustomEvent should not be used in OnRender. TriggerCustomEvent is used to sync the price/indicator data when a UI event occurs such as a mouse click or a button down event. Please remove that part from the OnRender method. To know what object you are accessing is null, you will need to add a null check for each object before running this line of code, but the issue could go away with the removal of TriggerCustomEvent.

    Best regards,
    -ChrisL

    Comment


      #3
      Hello Chris

      Thanks for your reply. I have exactly same indicator without TriggerCustomEvent and same error occurs at same bars.

      So, what do I have to check? What object?

      Sincerely,

      Comment


        #4
        Hi Impeesa, thanks for your reply.

        The chartScale is likely what is null here. If you simply ignore the calculation when the object is passed in null it should go away. The stack trace from Visual Studio should also give these details.

        Best regards,
        -ChrisL

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        81 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        42 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        64 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        66 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        54 views
        0 likes
        Last Post CarlTrading  
        Working...
        X