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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by RDTrader16, Yesterday, 10:19 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by f.saeidi, Today, 12:11 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by merc410, Today, 03:41 AM
        3 responses
        20 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by RaddiFX, Yesterday, 09:55 PM
        1 response
        21 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by elirion, Yesterday, 10:03 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X