Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator added with AddChartIndicator stop but strategy continues.

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

    Indicator added with AddChartIndicator stop but strategy continues.

    This is a problem that I have seen for some time on an intermittent basis. But I need to fix it now.

    Indicators that I add from the Strategy with AddChartIndicator, suddenly disappear from the chart but the strategy continues to work just fine. No messages in the log, no errors in Visual Studio or the compile. The instances of those indicators that the strategy adds disappear at the same time from the active indicator list.

    Any words of wisdom about what could be causing this these indicators to be removed like that?

    I also run logic on three other time frames. This basic system has been working fine for many months. But when I first start up after editing the strategy or just a cold start, those indicators sometime disappear after running a short time. It I disable and then re-enable the strategy they appear again and usually stay fine for the rest of the day.

    Could conflict between the added time frames and the primary somehow cause this?

    I apologize for bringing this up late of a Friday.

    Thank you.

    #2
    Hi JGRtrader, thanks for posting.

    We do not have other users writing in about this, and when I test a trivial script like the SampleMaCrossover strategy which adds chart indicators I can not reproduce this disappearing of the indicators. The problem you are seeing is either related to the strategy or the indicators it is using/adding. If possible, start by testing by adding an SMA and see if the SMA gets removed. If not, make a new strategy or reduce the current one and try reproducing this. If you can reproduce consistently with a reduced script I can test it on my machine as well. See the SampleMaCrossover strategy for a full example of how to add an indicator to a chart.

    Kind regards,
    -ChrisL

    Comment


      #3
      ChrisL

      Thank you for the reply. The indicators I am using are HMA10, HMA20 and SMA20 . Since no one else is reporting anything like this, it is not a known issue with a quick answer.

      To make a simplified version of this 5000 line program would be too big a project and very likely that simplified version would not cause the problem anyway. I have not spent a lot of time trying to get to the bottom of this but I will have to look at more depth now. My suspicion is that it may be related to conflict between my four time frames.

      I will try catching it in action with the debugger and/or write test code.

      Comment


        #4
        A little follow up. Still getting to the bottom of this. Current observations are.
        1. It is more likely to occur on Playback than with Live data.
        2. It occurs generally after startup. I have many series and maintain seven lists of class instances based on detected events at the three time frames and only one instrument.
        3. I observed an actual incident by recording the chart and Output on Snagit video. This allowed me to track diagnostic makers that I print. I caught the instant that the indicators and chart annotations disappear.
        4. What I saw twice, and can't explain, is that when I call (two different) class level methods from inside OnBarUpdate, with ListIndex equal greater than 1, it becomes equal zero once once inside the method.. When this happened, both times,two different time based events occurred in my code within one second.
        5. I check and re-checked the code and also where I set those indexies to 0 is in State.Configure. I clear the lists involved at the same time. That and my other Indexes are declared "private int" fields (using C# language).
        6. Today, I ran the script with all the relevant code and diagnostic print statement enabled and there was no repeat of what happened earlier.
        My current thinking is that I have some, nearly random, timing issue that may be allowing OnBarUpdate to be fired while it is still executing the previous event and the code goes rogue. Or maybe the Method is executed on a thread ahead of when code if completing the call to it. I have a LOT of diagnostic print statements which impact code execution time.

        The CPU utilization is generally between 6% and 9% and only about 12Gbyte of my 32Gbyte ram is used. The CPU is a 4.5GHz Intel Kaby Lake with 4 cores. Now discontinued but not a slouch.

        An additional observation is that one time only, I caught the CPU utiliztion way up about 45%. That lasted only a second or two. I don't know if that is related or not.

        Another thing that crosses my mind, is that computer crashes from time to time for no apparent reason. I could have a marginal hardware situation.

        Thanks for any help. I realize I have ventured into the expert range without being currently qualified to do so. This from an old retired engineer and one time circuit designer and firmware programmer who as managed to avoid C family software until now.
        Last edited by JGRtrader; 03-29-2022, 02:52 PM.

        Comment


          #5
          Hi JGRtrader, thanks for the follow up. We will need a reduced script that can consistently reproduce the issue to report this as a platform/ workspace issue.

          Kind regards,
          -ChrisL

          Comment


            #6
            Chris L,

            It appears that the problem is solved. I found two minor errors in my code and the event has not occurred since I corrected them. I had a hole in some logic that could let a zero index through and I had an incorrect index value for a list. That index was not zero but could be outside the range of the list. This did not create a run-time error. In their frequent updates, MS sent out updates to .NET components but I doubt if that had anything to do with this problem.

            Thank you.

            Comment


              #7
              Chris L,

              I take back my post of March 31. It was true that for two days it had run without the mysterious loss of the indicators added by "AddChartIndicator." The symptom is that the three indicators that the strategy puts in the chart's "Indicators" dialog would simply disappear and the strategy would continue running without a glitch.

              After a lot of diagnostic efforts (see below) One outstanding concern I have is my use of a lot of class level methods. I read on "NinjaScript Best Practices" that "Always assume that any of the methods you implement in NinjaScript could be called from another thread." All, of these methods are called from inside OnBarUpdate. They reference class level variables set in OBU and other methods and they populate class members of Lists and print to the Output window.

              Does OnBarUpdate wait for those methods to be completely executed before proceeding or are they executed asynchronously to the OBU code? If Asynchronous should I be using Dispatch and Lock to manage them? Could they be executed before actually being called? A few have parameters set in OBU.

              _________________________________

              Summary of my diagnostic efforts follows. At this time, Since I can see no effect on my script operation, I am continuing with it realizing that these indicators may not always display on the primary chart.

              Your request that I provide a simplified script that repeats this problem consistently, is impossible. It is an apparent random event and despite a LOT of work with added testing print statements etc. I have not been able to identify anything in the script that explicitly causes this. It must be associated with the large nature of my script. I saw no change regardless of the number of windows open and applications running. The events tended to come in batches and then not again for a one or more days.

              I have studied the "Muli-Threading Consideration for NinjaScript" and the posting in the forum "Using ThreadStatic attribute for multi-threading considerations" for which Kate left a very informative explanation. This quickly led to MS documentation on "Dispatch Class." I skimmed that but I am going down that long rabbit hole. But Kate's explanation made this whole issue a lot more clear to my old engineer's mind.

              What I have gleaned from all of this is that I have some threading conflict that impacts only the displayed chart running on the primary time frame. Since "windows" have their own thread, I am concluding that there is some conflict there. My computer is an ASUS Motherboard with 32 Gbyte RAM running an Intel Series 7, four core CPU clocking at 4.5 GHz. I did find that with my total of five different time frame series running at the same time, the fasted one being 20 Ticks, two do simultaneously call OnBarUpdate at the same millisecond several times a minute. I could not find any correlation between those occurrences and these indicator loss events. I seems that the computer/program handles these fine.


              Thank you.

              Comment


                #8
                Hi JGRtrader, thanks for the follow up.

                If you call a class level method from OnBarUpdate it will complete the method call. OnBarUpdate can be called from multiple threads so all the methods can be running on different threads, so the main concern is shared resources e.g. reading/writing a file. It depends on what your method has in it if it may be causing this problem where the indicator gets removed on its own.

                Comment


                  #9
                  Chris L,
                  Thank you, that helps. I may have shared resources. Please tell me it what I describe here could be causing a shared resource or other problem in my logic.

                  I update several lists, declared at the class level along with their index variable, and updated in class level methods called from OBU. Those lists and their indexes are declared at the class level at the start of the script and updated in my List Update methods. Those data are available by accessing the list with its current index at numerous places in the logic which is driven from inside OBU. That logic is placed in the OBU code after the List Update methods are called.

                  From the topic in this forum, "Using ThreadStatic attribute for multi-threading considerations" I see that charts live on a UI thread but the logic lives on Instrument threads. Assuming the class level methods that are all called from OBU are on Instrument threads, can I trust that there could be no conflict with the displayed chart, unless of course there is some shared resource which I am not aware of.
                  Last edited by JGRtrader; 04-08-2022, 02:03 PM.

                  Comment


                    #10
                    Hi JGR, If the list is at the class level it will exist in each instance of the class individually, so this is completely thread safe. Another place to check will be the Trace files and the Windows Event viewer program that comes with Windows. The Trace files can be found in Documents\NinjaTrader 8\trace.

                    Kind regards,
                    -ChrisL

                    Comment


                      #11
                      Chris L,

                      Thank you.

                      I am watching for something using the trace. I have been away from this for some days. I will continue running it, the strategy works fine so I can see the chart by opening another window and added the those three indicators by hand until I can identify what exactly is happening. My hunch is that it is a threading issue someplace.

                      Comment


                        #12
                        I have seen this happening on/off for years. Randomly, the strategy keeps running but all of the hosted indicators disappear from the chart. No error messages shown or exceptions. Nothing in Control Center Log tab, or the log file, or trace.

                        One approach is to just not use AddChartIndicator and put them on the chart yourself, but then it can be hard to keep the inputs synchronized.
                        Bruce DeVault
                        QuantKey Trading Vendor Services
                        NinjaTrader Ecosystem Vendor - QuantKey

                        Comment


                          #13
                          Just wondering if there was any progress on what may be causing this issue. I've been running into this intermittently over the last year or so as well. Starting some projects that use AddChartIndicator and noticing this more frequently.

                          The indicator will suddenly disappear completely from the chart even though the strategy seems to be working perfectly otherwise. Values for the indicator still print like normal even with the indicator missing.
                          It's random what causes this. Sometimes will disappear immediately after enabling. Other times, it happens after running the strategy for a while. Most of the times it works fine, but it happens often enough that it can be a bit annoying.

                          This happens with all indicators I've tried so far (Bollinger, Keltner, RSI, Stoch, ADX).

                          I am working with a pretty big file. But not really sure what could even cause it to disappear like that.
                          Using 8.1.3.1 64-bit
                          TradeSaber Inc.NinjaTrader Ecosystem Vendor - TradeSaber Inc.

                          Comment


                            #14
                            I have the same problem all last year. I created a few strategies which use a few MA and other indicators. Sometimes randomly the indicators disappear from the chart. No errors in Log... nothing... Clients don't like that indicators require a strategy restart to display...

                            Comment


                              #15
                              Hello QuantKey_Bruce, TradeSaber, vitaly_p,

                              Please create a reduce test script calling a simple indicator like the SMA and adding this with AddChartIndicator() and no other logic.

                              Ensure you are able to reproduce the behavior.

                              Then export the script and attach to your next post so that I may test. If I am able to reproduce I will report the behavior.

                              If the behavior cannot be reproduced, this might indicate an issue with the code in the custom script that is able to reproduce and would need further debugging.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Today, 05:17 AM
                              0 responses
                              50 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              126 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              69 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              42 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              46 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X