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

Error on executing DB command

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

    Error on executing DB command

    Hello,

    I receive the following error message with automation:

    Error on executing DB command: System.InvalidOperationException: There was an error reflecting type 'NinjaTrader.NinjaScript.Strategies.Testsystem'. ---> System.InvalidOperationException: There was an error reflecting field 'entryOrder'. ---> System.InvalidOperationException: There was an error reflecting type 'NinjaTrader.Cbi.Order'. ---> System.InvalidOperationException: There was an error reflecting property 'UserData'. ---> System.InvalidOperationException: There was an error reflecting type 'System.Xml.Linq.XDocument'. ---> System.InvalidOperationException: Cannot serialize member 'System.Xml.Linq.XDocument.Declaration' of type 'System.Xml.Linq.XDeclaration', see inner exception for more details. ---> System.InvalidOperationException: System.Xml.Linq.XDeclaration 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 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().

    Any idea why I get this error message? Unfortunately NinjaTrader does not indicate the line in the code where the error has occured.

    Gerik

    #2
    Hello Gerik,

    Is this error occurring when placing an order?

    If so, please try recreating the database.

    To rename the database:
    • Shutdown NinjaTrader
    • Open the Documents > NinjaTrader 8 > db folder
    • Right click on NinjaTrader.sdf and select "Rename"
    • Rename the file 'OLDNinjaTrader.sdf'
    • Finally, restart NinjaTrader


    Or is this error occurring when running a specific strategy?

    If so, does this error occur when testing the Sample MA Crossover included with NinjaTrader?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      I have renamed the database. Same issue.

      "private Order entryOrder" was defined as "public Order entryOrder" in the class of my strategy.

      This caused the issue.

      Thank you
      Gerik

      Comment


        #4
        Hello Gerik,

        Thank you for confirming this is coming from a NinjaScript Strategy.

        Yes, Order objects will need to be private.

        Below is a link to the help guide on Order which has example code.
        https://ninjatrader.com/support/help.../nt8/order.htm


        If the error is not occurring when placing an order, and is coming from a NinjaScript Strategy, renaming the database will have no effect as the error is being caused by running a strategy.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I have the same issue. When I add strategy to a chart (w/o enabling it) this error occurs. Or when I remove it. VS debugger doesn't help and my strategy works like a charm. How to trace what causes it?
          No issue with Sample MA Crossover.

          Comment


            #6
            Hello Leeroy_Jenkins,

            Thank you for confirming the issue does not occur with the Sample MA Crossover included with NinjaTrader, which would indicate the issue is with the code of the specific script.

            The next steps are to debug the script.

            Start by commenting out all code in OnBarUpdate(). Does the behavior still occur?
            Uncomment comment code until the error returns.
            What was the last line uncommented?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Nope, it didn't help. I found the problem - I have a field Template that hides inherited member StrategyBase.Template. Simple changing the name to template fixed this issue. Thank God it didn't take whole day to fix this lol.

              Comment


                #8
                Originally posted by Leeroy_Jenkins View Post
                Nope, it didn't help. I found the problem - I have a field Template that hides inherited member StrategyBase.Template. Simple changing the name to template fixed this issue. Thank God it didn't take whole day to fix this lol.
                Can you share your workaround with Template? I am interested in such a solution. I started a thread before, but it was too tall task for me.

                Comment


                  #9
                  Originally posted by UltraNIX View Post

                  Can you share your workaround with Template? I am interested in such a solution. I started a thread before, but it was too tall task for me.
                  I have filed like this:

                  private string Template;

                  But the base class StrategyBase has field or property with the same name. Every strategy inherits this base class. I might be wrong but I think NT tried to serialize this filed instead of base class filed. That's caused error.

                  Visual Studio shows this warning and all I have to do is rename Template to any other name. No more errors. If you don't use VS I encourage you do so, NT script editor doesn't show warnings like this.
                  Attached Files
                  Last edited by Leeroy_Jenkins; 05-05-2022, 03:20 AM.

                  Comment


                    #10
                    Can you share both files? Template and one of strategies? So I could see what is going on and what code needs to put where? If you don't want to do it in public, maybe you can PM me?

                    Comment


                      #11
                      Template is variable not a file. If you have problems with a strategy you can send it to me, I'll give it a look.
                      Attached Files

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by maybeimnotrader, Yesterday, 05:46 PM
                      5 responses
                      24 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by NRITV, Today, 01:15 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post NRITV
                      by NRITV
                       
                      Started by quantismo, Yesterday, 05:13 PM
                      2 responses
                      16 views
                      0 likes
                      Last Post quantismo  
                      Started by frankthearm, Today, 09:08 AM
                      6 responses
                      26 views
                      0 likes
                      Last Post frankthearm  
                      Started by adeelshahzad, Today, 03:54 AM
                      5 responses
                      33 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Working...
                      X