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

unhandled exception: object reference not set to an instance of an object

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

    unhandled exception: object reference not set to an instance of an object

    I started a NT8 strategy from sample LONGSHORTToolbarButtonsB5, tested different options and works perfectly with command buttons events (calling ATMstrategymethods, forcing close position, reversing position ... )

    Now I'm trying to program a ComboBox and the result is that it works but with some issues:

    - Object shows correctly in screen initial value selected in State.Historical
    setting comboButton.SelectedIndex = comboselection (int 0) during Invoke to create control grid

    - Object has 2 events programmed
    comboButton.LostFocus += comboButtonevent; - Print value on output window - Working
    comboButton.SelectionChanged += SelectedIndexChanged - Copies value index to textbox in control grid - Working

    The problem is that when I click and select an option the combobox gets the selected value, but has 2 issues
    - error message box "unhandled exception: object reference not set to an instance of an object"
    - Combobox text does not show the selected item on screen, stays with same text as begins. Text does not change but gets the selected value

    Uploaded a file "tradegrid.cs". It contains grid and combobox events, not strategy logic or commandbuttons events

    Maybe this is not a directly supported feature but any help would be very appreciated

    Thanks
    Attached Files

    #2
    Hello aog076, and thank you for your query. Please note that the scope of our support is limited to the help guide and, ocassionally, the MSDN C# documentation. Using ComboBoxes in NT8 is not a currently documented feature.

    We are currently reviewing the code you sent us. Thank you for sending us this information. We will get back to you shortly when we have more information.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      I'm just following your sample code in help guide "UserControlCollection"

      I intend to choose entry/exit methods with a combobox, is avoid to disable/enable the strategy every time

      I found that one of 2 issues is solved by setting properties AllowDrop = true and Iseditable = true; on combobox. With this properties combobox shows and applies selected index but I still get the error message. The control works but getting an error message every time is annoying

      Maybe in some point there's a need to use Dispatcher on some additional Event, but this goes far beyond my c# knowlege, I think it's not difficult for an expert programmer to solve this and it's an interesting issue for other users

      I upload the strategy with modifications to show that the only issue is getting an error message every time selection is switched, even that combobox control is working fine
      Attached Files
      Last edited by aog076; 09-14-2016, 03:20 PM.

      Comment


        #4
        Thank you for this additional information. I agree that simplifying things will make it easier for our forums users to assist you with your .NET design, and we will be happy to provide direct assistance within the scope of NinjaTrader and NinjaScript.

        I would like to mention that generally speaking "object reference not set to an instance of an object" , especially with a controller such as a button which needs a backing method, is usually an indication that something your code expected was not present. To avoid this, I would highly recommend creating a combobox as close to that in the example code Microsoft provides in their publicly available documentation here, https://msdn.microsoft.com/en-us/lib....combobox.aspx . Once you have a "hello world" combobox, with no dynamic information from Ninja, you can then refactor this in small steps using more and more dynamic Ninja data until it operates the way you would like.

        In particular, you will want to pay careful attention to how addButton_Click is used in that example. At a bare minimum, I recommend you ensure you have a callback method that resembles addButton_Click , and that you are adding a reference to this callback to every button you intend on pressing.

        To make debugging much easier, I recommend trying to repair this in NinjaTrader 8, using our new enhanced Visual Studio debugging. You can learn more about this here,



        and at Microsoft's publicly available documentation link on Visual Studio debugging here,



        We are happy to help with any specific NinjaScript questions that come up.
        Jessica P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Tim-c, Today, 03:54 AM
        0 responses
        3 views
        0 likes
        Last Post Tim-c
        by Tim-c
         
        Started by FrancisMorro, Today, 03:24 AM
        0 responses
        2 views
        0 likes
        Last Post FrancisMorro  
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,771 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        31 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        945 views
        0 likes
        Last Post spwizard  
        Working...
        X