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

Strategie calculation does not work

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

    Strategie calculation does not work

    Hey guys,


    I have develop a automatic Strategy.
    In itself, it works great, but in some situations is no longer calculated.
    But I don´t know why.

    The amazing thing is that it does not work if I disable the strategy and reactivate it.
    The strategy is enabled but it is not calculated in Status.RealTime. It only calculated the Status.Historical

    But when I removed the strategy and restarted it will be calculated again in Status.Historical and Status.Realtime.


    Do you have an idea why the strategy does not switch to Status.RealTime and calculated?


    Best regards
    Martin


    #2
    Hello Martin89,

    Thanks for your post.

    When you apply the strategy, please check the "strategies" tab of the Ninjatrader control center and observe the color of the strategy name. If it is Green then the strategy is ready to place live trades. If it is yellow/orange then the strategy is not ready to place live trades and is waiting to complete that last historical trade. Please see, " Understanding the strategies tab" on this page of the help guide: https://ninjatrader.com/support/help...tegies_tab.htm

    If when you apply the strategy and check the name color in the strategies tab and the color is not green or yellow then look to make sure that the "enabled" check box on the right of that row is checked. If it is not checked and you then check it and it immediately unchecks, please look at the "Log" tab of the control center for any run time error messages related to the strategy.

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hey NinjaTrader_PaulH

      Thanks for your fast replay.

      I'm very familiar with the strategy tab and the different colors of the strategy names.

      When the error occurs everything is fine.
      The strategy is activated, the strategy name is green in the strategy tab and the historical filling process is complete without error messages in the log tab or in the output window.
      But in the Status.Realtime the strategy does not continue.
      No errors. No calculation.Nothing happens.


      I suspect that it's because I hide some standard NinjaTrader parameters in the UI.
      Can this be possible?


      I hide the following parameter in the propertie region:

      [Browsable(false)]
      public new Calculate Calculate {get;set;}

      [Browsable(false)]
      public new string Name {get;set;}

      [Browsable(false)]
      public new MaximumBarsLookBack MaximumBarsLookBack {get;set;}

      [Browsable(false)]
      public new int BarsRequiredToTrade {get;set;}

      [Browsable(false)]
      public new StartBehavior StartBehavior {get;set;}

      [Browsable(false)]
      public new OrderFillResolution OrderFillResolution {get;set;}

      [Browsable(false)]
      public new bool IsFillLimitOnTouch {get;set;}

      [Browsable(false)]
      public new double Slippage {get;set;}

      [Browsable(false)]
      public new int EntriesPerDirection {get;set;}

      [Browsable(false)]
      public new EntryHandling EntryHandling {get;set;}

      [Browsable(false)]
      public new StopTargetHandling StopTargetHandling {get;set;}

      [Browsable(false)]
      public new SetOrderQuantity SetOrderQuantity {get;set;}

      [Browsable(false)]
      public new TimeInForce TimeInForce {get;set;}



      Thank you for your help.


      Best regards
      Martin

      Comment


        #4
        Hello Martin,

        Thanks for your reply.

        Please add a print statement in OnBarUpdate() to provide a print showing the state.

        For example: Print (Time[0]+" State: "+State);

        Using your properties, on my end this is what I see:

        11/20/2019 9:11:00 AM State: Historical
        11/20/2019 9:12:00 AM State: Historical
        11/20/2019 9:13:00 AM State: Historical
        Enabling NinjaScript strategy 'Martin89test/185718290' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=By strategy position ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
        11/20/2019 9:14:00 AM State: Realtime
        11/20/2019 9:15:00 AM State: Realtime
        11/20/2019 9:16:00 AM State: Realtime

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hey Paul,

          I already had the idea and realized that I only came to State.Historical.

          I noticed that this only happens if the strategy of NinjaTrader (ConnectionLoss or RealtimeError) was closed. I was able to activate the strategy afterwards, but she did not switch to Status.RealTime.

          But if I remove the strategy and add it back in, it will work again.





          Comment


            #6
            Hello Martin,

            Thanks for your reply.

            Please disconnect from your data feed, close Ninjatrader, restart NinjaTrader and verify you have live charts.

            Remove your strategy from the chart (or strategy tab).

            Use print statement I provided, recompile your strategy and apply the strategy to a live chart verify the strategy is processing in real time.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hi Paul,

              I made it as you said and detect the following:

              The strategy was closed from NinjaTrader during the night due to connection lost and activated not again.

              When I activated the strategy from the "Strategie" Tab the next morning, the strategie name was green but she did not switch to the State.Realtime.

              Only after i activated the strategy in the chart via the strategy menu did she switch to the Status.Realtime.

              How can i change it that the strategie switch to the State.Realtime when she actived from the "Strategie" Tab after close connetion lost?

              Comment


                #8
                Hello Martin89,

                There wouldn't be anything that would be stopping the strategy from transitioning to realtime data when it is enabled from the Control Center. There just needs to be iterating realtime data.

                If you add a print Print("Reached State.Realtime"); in OnStateChange when State == State.Realtime, you should see this print in the output window when there is realtime data. Once realtime data starts iterating, you should be able to observe the following print in the output window.

                Code:
                        protected override void OnBarUpdate()
                        {
                            if (State == State.Realtime)
                            {
                                Print("Processing Realtime Data");
                            }
                        }
                I have attached a strategy that can test these prints. I would suggest testing the same in your strategy after testing this script. If you are hitting issues with your strategy, I suggest checking the log tab of the Control Center for any errors that would cause the strategy to abort, or if your logic is not allowing these prints to be reached.

                If you have an issue with this test strategy, please let us know.
                Attached Files
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Okay, I will test it.
                  And give you an info which status is reached in case of error.

                  I also see no reason why the strategy stop. Because the Strategie works.
                  In any case, I see no erros in the Log tab.
                  The only error I get so far is that the strategy no longer changes to the status Real.Time after there was a connection loss error. (At my customers too!)
                  But only if the strategy is already over 20 hours running.
                  Could this possibly be a reason? (The strategy is calculated OnPriceChange)

                  Comment


                    #10
                    Hello Martin89,

                    Below is a video showing the steps I have taken with the test strategy. If you can hit the issue with this test strategy, please let me know any specifics I'll need to reproduce on my end.

                    Demo - https://drive.google.com/file/d/1UE-...w?usp=drivesdk

                    If you are hitting this issue only with your strategy, I would suggest commenting sections of code until the issue is identified in the strategy logic or until we have a small example that can demonstrate the issue and we can use to file a report. If you are able to modify the test strategy so it can reproduce the behavior, that will be a way forward as well.

                    I look forward to assisting.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      Hey Guys,
                      thank you for the great support.
                      I was able to locate the error.
                      Check it out on the video.


                      The error occurs when I do AddDataSeries().
                      Why is that?

                      Comment


                        #12
                        Video Link: https://1drv.ms/v/s!AiggzbZvxGnxg6Nx...6RwAA?e=PbFqqg

                        Comment


                          #13
                          And the Error on the RealtimeTest Strategie: https://1drv.ms/v/s!AiggzbZvxGnxg6Ny...Dr6rA?e=7xKBVT

                          Comment


                            #14
                            Hello Martin89,

                            I have added the AddDataSeries call to the script and I am not seeing the same behavior. I see prints for both data series. My previous example had Calculate default to Calculate.OnBarClose. Could you verify that you are testing with Calculate set to OnPriceChange?

                            Could you also confirm that you are seeing this issue on the current build, release 20? Updates can be downloaded here - https://ninjatrader.com/PlatformDirect

                            I've attached a new RealtimeTest script with the modifications suggested to include AddDataSeries(). Please attach a modification to this script that includes the necessary modifications if I am missing any.

                            We should also consider testing in a clean environment to rule out any installation issues.

                            Clean environment test

                            Creating a clean environment can be done by following the steps below:
                            1. Close NinjaTrader 8, and rename the "NinjaTrader 8" folder in My Documents to something like: "NinjaTrader 8 OLD"
                            2. Uninstall NinjaTrader from the Windows Control Panel and reinstall using the installer from http://ninjatrader.com/PlatformDirect
                            3. Import the test script(s) and set up your connection. Please verify if we can hit the issue in this environment
                            If you ever need to switch back to your original platform, you may do so by closing NinjaTrader and swapping the platform folder names.
                            For example, Close NinjaTrader and rename the new "NinjaTrader 8" folder to "NinjaTrader 8 NEW" and the "NinjaTrader 8 OLD" folder to "NinjaTrader 8." Then restart the platform. Simply put: NinjaTrader 8 will always load the "NinjaTrader 8" folder in My Documents.

                            If we are still hitting issues at this point, I would like to get connected to your PC to observe the tests with you and to take note of anything else we need to get the behavior reproduced on our end so we can report it. Please then message me at platformsupport [at] ninjatrader [dot] com with the text "Attn Jim 2339193" and a link to this thread. I will be available to schedule a call between 9AM EST and 5PM EST Monday through Friday.

                            I look forward to resolving this matter with you.
                            Attached Files
                            JimNinjaTrader Customer Service

                            Comment


                              #15
                              Hello Jim,
                              thanks for the great support.
                              I will take the steps explained and see if the error occurs again.

                              I will contact you as soon as I know more.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by gemify, 11-11-2022, 11:52 AM
                              6 responses
                              803 views
                              2 likes
                              Last Post ultls
                              by ultls
                               
                              Started by ScottWalsh, Today, 04:52 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by ScottWalsh, Today, 04:29 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by rtwave, 04-12-2024, 09:30 AM
                              2 responses
                              22 views
                              0 likes
                              Last Post rtwave
                              by rtwave
                               
                              Started by tsantospinto, 04-12-2024, 07:04 PM
                              5 responses
                              70 views
                              0 likes
                              Last Post tsantospinto  
                              Working...
                              X