Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Serializable Instrument Input

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

    Serializable Instrument Input

    Hello,

    Using this bit of code as an instrument input parameter for an indicator.

    Code:
    [NinjaScriptProperty]
    [TypeConverter(typeof(NinjaTrader.Gui.Tools.Instrum entSelector))]
    [Display(Name="Select Execution Instrument",GroupName = "Parameters", Order = 1)]
    public NinjaTrader.Cbi.Instrument InstrumentInput
    { get; set; }
    When trying to save the indicator to a chart I get the "There was an error reflecting type" error message. So it's an issue with XML. I double-checked the other properties and they are ok. The only one is this one... which is not a string. How does one convert to a string and back? I noticed there's a method called InstrumentDeserialized, not sure if that will help.

    Thanks
    Unsuitable
    NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

    #2
    Hello Unsuitable,

    The Instrument object is not serializable, you would need to make a string property for the instrument name to be saved. This is just like a Brush or any other C# object that cannot be serialized.

    You can make a serialize property like the following:

    Code:
    [XmlIgnore]
    [TypeConverter(typeof(NinjaTrader.Gui.Tools.Instrum entSelector))]
    [Display(Name="Select Instrument", GroupName = "Parameters", Order = 0)]
    public Instrument InstrumentInput
    { get; set; }
    
    [Browsable(false)]
    public string InstrumentInputSerializable
    {
    get { return InstrumentInput.FullName; }
    set { InstrumentInput = Instrument.GetInstrument(value); }
    }
    Please let me know if I may be of further assistance.

    Comment


      #3
      Hello Jesse,

      Yup that's what I figured, wasn't quite sure how to convert it. It works. I noticed you removed the [NinjaScriptProperty] tag, is it required?

      Thanks
      Unsuitable
      NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

      Comment


        #4
        Hello Unsuitable,

        You would only need that for optimization properties or ones which should be included in the indicators constructor.




        Please let me know if I may be of additional assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        54 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        72 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        38 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        99 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        60 views
        0 likes
        Last Post PaulMohn  
        Working...
        X