Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on executing DB command: System.InvalidOperationException

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

    Error on executing DB command: System.InvalidOperationException

    Hi,

    During the test of a strategy we get this exception randomly. Was investigating and cannot understand what is the reason for that...
    InstrumentInput1 is NinjaTrader.Cbi.Instrument object

    I am starting to suspect that this problem is because of the data provider but am not sure... We are using Interactive Brokers account for testing

    Thank you in advance

    P.S.
    If you need any additional info just let me know


    2020-09-07 15:55:55:011|3|524288|Error on executing DB command: System.InvalidOperationException: There was an error reflecting type 'NinjaTrader.NinjaScript.Strategies.TestStrat.Test StrategyV1'. ---> System.InvalidOperationException: There was an error reflecting property 'InstrumentInput1'. ---> System.InvalidOperationException: There was an error reflecting type 'NinjaTrader.Cbi.Instrument'. ---> System.InvalidOperationException: Cannot serialize member 'NinjaTrader.Cbi.Instrument.HistoricalData' of type 'NinjaTrader.Data.BarsBytes[]', see inner exception for more details. ---> System.InvalidOperationException: NinjaTrader.Data.BarsBytes cannot be serialized because it does not have a parameterless constructor.
    --- End of inner exception stack trace ---
    at System.Xml.Serialization.StructModel.CheckSupporte dMember(TypeDesc typeDesc, MemberInfo member, Type type)
    at System.Xml.Serialization.StructModel.GetPropertyMo del(PropertyInfo propertyInfo)
    at System.Xml.Serialization.StructModel.GetFieldModel (MemberInfo memberInfo)
    at System.Xml.Serialization.XmlReflectionImporter.Ini tializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
    at System.Xml.Serialization.XmlReflectionImporter.Imp ortStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)
    at System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
    --- End of inner exception stack trace ---
    at System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
    at System.Xml.Serialization.XmlReflectionImporter.Imp ortAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, String ns, Type choiceIdentifierType, Boolean rpc, Boolean openModel, RecursionLimiter limiter)
    at System.Xml.Serialization.XmlReflectionImporter.Imp ortFieldMapping(StructModel parent, FieldModel model, XmlAttributes a, String ns, RecursionLimiter limiter)
    at System.Xml.Serialization.XmlReflectionImporter.Ini tializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
    --- End of inner exception stack trace ---
    at System.Xml.Serialization.XmlReflectionImporter.Ini tializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
    at System.Xml.Serialization.XmlReflectionImporter.Imp ortStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)
    at System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
    --- End of inner exception stack trace ---
    at System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
    at System.Xml.Serialization.XmlReflectionImporter.Imp ortElement(TypeModel model, XmlRootAttribute root, String defaultNamespace, RecursionLimiter limiter)
    at System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
    at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
    at NinjaTrader.NinjaScript.StrategyBase.ToXml()
    at NinjaTrader.NinjaScript.StrategyBase.DbAdd()
    at NinjaTrader.NinjaScript.StrategyBase.DbUpdate()
    at NinjaTrader.Cbi.DB.DBThread()

    #2
    Hello vlaladim, thanks for writing in.

    Can you please test on a new database file? If the same problem happens on a new database, I could take a look at an example script that is able to reproduce the problem.

    Instructions to reset your database:
    • Shutdown NinjaTrader and Go to the Start Menu
    • Select My Documents--> NinjaTrader 8--> db--> "NinjaTrader.sdf" file (may only say 'NinjaTrader' depending on your Windows File Explorer settings)
    • Right click on NinjaTrader.sdf and select "Rename" *Name it "OLDNinjaTrader.sdf"
    • Then restart the software and NinjaTrader will create a fresh database file to use
    • Unfortunately the following items stored in the old database will be lost - Trading Hours templates, Instrument Lists / Custom Instruments, historical trade execution data, saved Strategy Analyzer backtest results

    You can reverse this process to get your old database back.

    I look forward to hearing from you.

    Comment


      #3
      Hi Chris,
      Honestly to tell you I am not sure that this exception is affecting the performance of the strategy but is worrying us. It is three instruments strategy. For each instrument I am adding separate dataseries. Will try to reproduce the problem with short and simple script and will publish it here

      Comment


        #4
        Hi Chris,
        I am attaching a short strategy script with which you can replicate the exception. I am starting to wonder should I use manually inputted string on the place of the Instruments parameters.
        I know that in this way we will have to insert the instrument names manually (not by using the mouse and selecting them from a list). But if this is the only solution just tell me to know not to continue experimenting.

        Thank you in advance

        Attached Files

        Comment


          #5
          Hello vlaladim, thanks for sending that in.

          The only thing that is different from the Instrument selector example is not [NinjaScriptProperty] tag above the parameters.
          I did this and have no advers effects when loading the strategy:

          Code:
          [NinjaScriptProperty]
          [TypeConverter(typeof(NinjaTrader.Gui.Tools.Instrum entSelector))]
          [Display(Name = "Instrument 1", GroupName = "Parameters", Order = 0)]
          public Instrument InstrumentInput1
          { get; set; }
          
          [NinjaScriptProperty]
          [TypeConverter(typeof(NinjaTrader.Gui.Tools.Instrum entSelector))]
          [Display(Name = "Instrument 2", GroupName = "Parameters", Order = 1)]
          public Instrument InstrumentInput2
          { get; set; }
          
          [NinjaScriptProperty]
          [TypeConverter(typeof(NinjaTrader.Gui.Tools.Instrum entSelector))]
          [Display(Name = "Instrument 3", GroupName = "Parameters", Order = 2)]
          public Instrument InstrumentInput3
          { get; set; }

          We do not recommend using variable inputs for the AddDataSeries method, so if that will not work use an input string. You may have a look at the "Correlation" indicator that comes with the platform for an example on safely using a string variable with AddDataSeries.

          Kind regards.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          59 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          134 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X