Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Instrument selector property error

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

    Instrument selector property error

    Hello again, I have a problem, in a strategy loaded on a chart I want the strategy to enter a different instrument, which it does perfectly, the problem is that I want that instrument to be selectable.

    I also have this part resolved like this in properties;
    [NinjaScriptProperty]
    [XmlIgnore]
    [TypeConverter(typeof(NinjaTrader.Gui.Tools.Instrum entSelector))]
    [Display(Name="Instrument to work", GroupName = "Instrument", Order = 45)]
    public NinjaTrader.Cbi.Instrument InstrumentInput
    { get; set; }

    The problem is that it does not save the selection once I close and open NinjaTrader, if I enter the strategy or edit it, it does retain that value, but if I close and reopen NinjaTrader, it has not saved it and the value appears empty.

    Also for this reason I get the following error in the log when starting Ninja

    Error on getting property 'InstrumentInput' for strategy '/258848593/258848593': Object reference not set to an instance of an object.​

    #2
    Hello RubenCazorla,

    Thank you for your post.

    Have you set a default instrument in State.SetDefaults?

    You need additional code in the getter and setter as well for it be serialized in xml.

    Please see my attached sample script demonstrating how to do this.



    This object reference error means something you are accessing in your script has not been created at the time you are accessing it. If the object is the Instrument you are trying to save, this could be why you are not able to save it properly.

    To determine what the source of the error is you will need to debug your strategy. This is typically done with print statements added to your code to send a print output to the New>Ninjascript Output window.

    Since you don't know where the error is, you would add a print statement every few lines of code and then observe the output window when you apply the strategy.

    Below is a link to a forum post that demonstrates using informative prints to understand behavior.



    Please let me know if I can assist further.
    Attached Files

    Comment


      #3
      Here was the problem, I didn't have this part, thank you so much

      // serialize the instrument input
      [Browsable(false)]
      public string InstrumentInputSerialize
      {
      get { return InstrumentInput.FullName; }
      set { InstrumentInput = Instrument.GetInstrument(value); }
      }​

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      53 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X