Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnStateChange() triggering State.Terminated repeatidly

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

    OnStateChange() triggering State.Terminated repeatidly

    Guys - this event when starting my strategy "now" is triggering a ton of times while it loads before triggering RealTime.

    I am still hunting down a bug that doesn't occur on SIM but does on NT Continuum.

    Frustrated,

    #2
    Hello MarketAlly,
    Thanks for your post.

    What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 7.0.1000.X or 8.0.X.X)

    Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?

    Is "now" the name of your strategy or this a print you are seeing in your NinjaScript Output window?*

    What is the "bug" you are trying to track down?
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      8.0.15.1 64-bit

      The crux of the issue I am trying to resolve is something that appears to be a thread issue around race condition that the SIM account doesn't do but the live continuum does. I only stumbled on the the terminate event after looking at my logs which I log all activity. In the case of the Terminate, I have a specific message that is logged when that happens and saw it triggering multiple times prior to Realtime state; triggering a few 40-50 times

      As for the issue I am trying to resolve, it looks like a cross thread issue around the way events are handled with Live orders during the OnExecutionUpdate state since I record a order record that I use to track concurrency for my multitimeframe strategy. Under SIM, this works perfect, as well as Playback - but when I go to Live, the underlying ORM I use will lose state. This has only ever occurred for me when a different method of awaiting asynchronous executions is done. I find it odd and have pulled my hair out trying to identify it since I must have this work to ensure the subsequent profit/stop orders are set correctly. It only happens on Live accounts (broker I am using is NT Continuum)

      I am trying a few methods of approaching the issue differently, but I did see this. And I am sorry I cannot make an example, my strategy is quite complex at over 5400 lines and it is only as connector to my backend system which I use you to only handle order transactions.

      Every error that could happen is trapped in my system and logged. I do this because I cannot have a strategy die and not handle issues if the box is unintended. So a lot of effort around keeping your system running in the event of an error has been done.
      Last edited by MarketAlly; 10-02-2018, 12:56 PM.

      Comment


        #4
        In regards to State.terminated being triggered multiple times, NinjaScripts will be cloned twice when the Indicators menu is brought up. The first time is to list the indicators and the second time is to populate the properties grid with the properties of the selected indicator. State.SetDefault and State.Terminated are passed in these clone events. If you can provide a watered down sample that enters State.Terminated 40-50 times before reaching State.Realtime I would be happy to take a look.

        Publicly available information on the NinjaScript LifeCycle can be referenced here -


        In regards to the crossthreading issue I do not have any recommendations. I know you said that your code is complex, but if we can reduce it down to a sample then I can possibly have Quality Assurance take a look.
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          I will be visiting Denver the week of October 15-19, if you would like I can stop in and show you the issue. I have successfully trapped it by logging the event, placing the record in an array and saving it once out of the event handler for that specific instance of new orders placed by NT Continuum which is reproducible every time but works perfect in both Sim and Playback.

          My belief is that under SIM/Playback, all events that are triggered on the platform come from the same main thread the strategy runs under. This meant the db libraries would access the database on the same thread instance. But when NT calls a live broker, that is managed on another thread and not rejoined to the strategy thread when it triggered the trade execution the first time therefor when my db libraries try to access the database it is getting random errors for writing in the underlying object which I am seeing. All closing executions do in fact work correctly and they are executing the same code as the opening transactions. This is my theory since no other reason it would work on SIM and not live with identical code.
          Last edited by MarketAlly; 10-04-2018, 04:58 PM.

          Comment


            #6
            Unfortunately I will not be able to assist outside of this public forum. If you can show a sample that produces this behavior I will be happy to take another look.
            Josh G.NinjaTrader Customer Service

            Comment


              #7
              I am trapping the issue but to be honest... it is disheartening. When 8.0.1 was released I reported an issue with a method that calculated MA on multi-timeframes. It was denied and it messed up my calculations and was forced to use the RC version until 8.0.3 when it returned to calculating the data correctly. I know cause I record all markers and calculations in my db and saw the values align once more when I test each release.

              In either case, this issue is happening on that event for impacting live data only. I will keep an eye for future releases when the issue stops.
              Last edited by MarketAlly; 10-05-2018, 10:42 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by fitspressoburnfat, Today, 04:25 AM
              0 responses
              2 views
              0 likes
              Last Post fitspressoburnfat  
              Started by Skifree, Today, 03:41 AM
              1 response
              4 views
              0 likes
              Last Post Skifree
              by Skifree
               
              Started by usazencort, Today, 01:16 AM
              0 responses
              1 view
              0 likes
              Last Post usazencort  
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              603 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              23 views
              0 likes
              Last Post xiinteractive  
              Working...
              X