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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      79 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 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