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:

    Hi All,

    I get the following error messages when running strategy in playback mode in max over a couple of weeks and without fail always get this for a particular strategy i am running.

    Code:
    Error on executing DB command: System.Data.SqlServerCe.SqlCeException (0x80004005): A duplicate value cannot be inserted into a unique index. [ Table name = Executions,Constraint name = PK__Executions__0000000000000300 ]    at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)    at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommandText(IntPtr& pCursor, Boolean& isBaseTableCursor)    at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)    at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()    at NinjaTrader.Cbi.Execution.DbAdd()    at NinjaTrader.Cbi.DB.DBThread()
    Im sure this is the strategy as very complex unmanaged strategy with error handling = ignoreAll with multiple orders exits with each order handled individually through onOrderUpdate and OnExecutionUpdate.

    If i disable the strategy the error messages still appear every 10 seconds until i reset the DB and close and reopen NT

    What are the common issues that could be causing this type of error and the areas of code i should focus on?
    Any pointers would be greatly appreciated in order to debug this and resolve.

    Thankyou

    **Edit** On further investigation, it would appear after resetting the DB, the strategy is fine during playback and the error only appears when disconnecting from playback or enabling/disabling the strategy to change settings and re-run. As soon as the Database error appears, all future runs of the strategy fail and dont run correctly. So it seems the moment get this error all future runs do not work correctly as the strategy is designed. So what is causing this initial failure?
    Last edited by mr_trade; 11-27-2020, 05:33 AM.

    #2
    Hello mr_trade,

    Thank you for the post.

    In your edit you mentioned that disconnecting/reconnecting seems to be the factor here. Are you seeing that the strategy remains in the control center and allows you to re enable the same instance? Generally when working with playback you would connect and then apply new instances of the strategies you wanted to test, in the situation where you see the error does it work if you instead apply a new instance?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thankyou Jesse,

      Yes if I follow a strict way of closing the strategy removing the strategy from strategies tab and then disconnect I don’t get the error it seems. Although it’s very intermittent I can’t always replicate the error just disconnecting from playback, it’s something around the area of disconnecting an active strategy, but not 100% sure. It’s clearly something in the strategy of using a more straight forward managed strategy or a simplified version of the unmanaged I don’t get these errors. What is the error eluding to? What is the duplicate that has been created in the DB? Something around order placement?

      Thankyou

      **EDIT**
      I thought i would strip the strategy back and see if its possible what i am trying to do with the managed approach.
      Using the samples provided on EntryHandling and EntriesPerDirection, is it possible to have 1 "fromSignal" which can be recycled for various entry and re-entry logic, this way the entriesPerDirection can be used to keep scaling in a position, and each position can have 2 or more profit targets as defined by a variable in the parameters.
      From the tests i have done, it appears from the samples provided you can only split the entry into individual profit targets by using seperate "fromSignal" for each.
      So i would need to define 2 entries in "EntriesPerDirection" which isnt correct, because it is only 1 entry but has 2 parts.
      Is it possible to use managed approach to handle multiple entries and re-entries on a given signal, with each entry having multiple Profit Targets and associated stoploss's?

      Thanks again.
      Last edited by mr_trade; 11-28-2020, 10:00 AM.

      Comment


        #4
        Hello mr_trade,

        Thank you for the reply.

        It’s clearly something in the strategy of using a more straight forward managed strategy or a simplified version of the unmanaged I don’t get these errors. What is the error eluding to? What is the duplicate that has been created in the DB? Something around order placement?
        Just to clarify, you don't see this happening with more simple scripts like the SampleMACrossOver and just with some logic you have used? I couldn't really say what that may be from the details so far, it could relate to some combination of logic you used and the situation its being used in. The error in some way relates to the database and potentially executions from the given error.

        Using the samples provided on EntryHandling and EntriesPerDirection, is it possible to have 1 "fromSignal" which can be recycled for various entry and re-entry logic, this way the entriesPerDirection can be used to keep scaling in a position, and each position can have 2 or more profit targets as defined by a variable in the parameters.
        From the tests i have done, it appears from the samples provided you can only split the entry into individual profit targets by using seperate "fromSignal" for each.
        So i would need to define 2 entries in "EntriesPerDirection" which isnt correct, because it is only 1 entry but has 2 parts.
        Is it possible to use managed approach to handle multiple entries and re-entries on a given signal, with each entry having multiple Profit Targets and associated stoploss's?
        From the managed approach you would need to use individual signal names for each step in your total position. If you scaling out that means you would need to have at least one entry with a signal name and two total entries, that would separate part of the position for the exits to target. That means two entries so you would need to use either Unique Entries for the entry handling or use 2 entries per direction because it is actually 2 entries. When you try to scale out of a whole position that was created with a single entry that can lead to problems with the targets and incorrect quantities. I am not sure if this is related to the error you had seen, I have not seen that in the past.


        I look forward to being of further assistance.






        JesseNinjaTrader Customer Service

        Comment


          #5
          mr_trade, thank you for this post.
          I have the same issue.

          NinjaTrader_Jesse thank you for your assumption about unique entry names. I am using Unmanaged orders and always provide the unique name (I just have a counter and I am adding number to signal name) for each signal. So, there should be another reason.

          fx.practic
          NinjaTrader Ecosystem Vendor - fx.practic

          Comment


            #6
            Hi fx.practic,

            in the end I had to go managed approach because even after getting it working multiple targets and entries isn’t possible to be paired or matched so was pointless exercise doing it in unmanaged luckily I didn’t need multiple working orders so managed approach worked ok for that purpose.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by guillembm, Today, 11:25 AM
            0 responses
            2 views
            0 likes
            Last Post guillembm  
            Started by Mongo, Today, 11:05 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Tim-c, Today, 10:58 AM
            1 response
            2 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by traderqz, Yesterday, 09:06 AM
            4 responses
            26 views
            0 likes
            Last Post traderqz  
            Started by traderqz, Today, 12:06 AM
            4 responses
            7 views
            0 likes
            Last Post traderqz  
            Working...
            X