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

Some signals do not show in real-time but shows in refreshed chart

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

    Some signals do not show in real-time but shows in refreshed chart

    Hello,

    I am writing an indicator that will plot buy/sell signals as up/down arrows based on a set of conditions.

    I am having this weird problem where when running the indicator in real-time with CalculateOnBarClose as false, the signal did not appear on some bars when it should. After I press F5 to refresh the chart, the signal appears. I am using a 1-min chart.

    Shouldn't the real-time run be more 'sensitive' since it is responding to incoming tick data, whereas the refreshed version is less sensitive (I presume the historical bars are processed once per bar?) That's why I am puzzled that the refreshed version has the signal showing up correctly while running it real-time the signal doesn't show.

    Any ideas what could be causing this?

    #2
    Hello wintermelon,

    Are you verifying the values you are getting in real-time vs the ones that you are getting with historical data with the Print() statement?



    Happy to be of further assistance.
    Last edited by NinjaTrader_JC; 03-05-2013, 10:46 AM.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thanks for your suggestion JC. Its going to be difficult to use the Print statement because my indicator is running on COBC = false, so it will likely be a mess to plough through the prints.

      Was hoping that you might catch some rookie common mistake that would produce that behavior, but if its not obvious, then I'll have to see if it happens again to figure it out at that time.

      Thanks for your help.

      Comment


        #4
        Hello wintermelon,

        You are correct in that having set COBC to false will be more sensitive to changes and that reloading will process it on historical data which is COBC true during that period.

        If post a snippet of your code when you are drawing the arrow, I can take a look at it.

        Happy to be of further assistance.
        JCNinjaTrader Customer Service

        Comment


          #5
          Hi JC,

          After many iterations of inserting print statements and waiting for the problem to re-occur, I've traced the problem to an incorrect output from the Swing.SwingHighBar function (probably the SwingLowBar function has the same issue as well).

          I have a 3-min chart, where I have the Swing indicator shown. The indicator I am writing generates buy/sell signals, and uses the swing highs / lows from the Swing indicator.

          Debug Print statements:
          SGXNK 06-13 - 27/3/2013 10:36:00 AM (+8 GMT) -
          lastSwingHigh = 12500 at 2 bars ago
          secondLastSwingHigh = 12495 at 11 bars ago

          The print statements showed that the SwingHighBar function returned a swing high 11 bars ago, which is not correct. The Swing indicator dots plotted on the chart also did not identify that bar as a swing high (which is correct). The swing high 2 bars ago is correct.

          When I hit F5 to refresh the chart, the problem vanished. So basically the Swing.SwingHighBar gave the wrong info when running it in realtime (COBC = false) compared to running it on historical bars.

          I don't know if this is relevant to the issue, but my indicator is being run on a 1-min chart. I've added the 3-min series like so: Add(PeriodType.Minute, 3), and I'm using the following statements for the swings.

          Code:
          secondLastSwingHigh = Swing(BarsArray[1], strength).SwingHighBar(0, 2, 90);
          lastSwingHigh = Swing(BarsArray[1], strength).SwingHighBar(0, 1, 90);
          Print("lastSwingHigh = " + Highs[1][lastSwingHigh] + " at " + lastSwingHigh + " bars ago");
          Print("secondLastSwingHigh = " + Highs[1][secondLastSwingHigh] + " at " + secondLastSwingHigh + " bars ago");
          Any ideas on why the Swing indicator function is returning the wrong values? or fixes?

          Thanks.

          Comment


            #6
            Hello wintermelon,

            The Swing indicator can have its plot points recalculated as incoming data is updated, thus making it challenging to use via programmatic calls. It is first and foremost mean to be used as visual trading tool.

            With that said you can still use the indicator for your calculations but would need to understand what price points can be accessed at which time programmatically, since those can be different from the historically plotted ones.
            JCNinjaTrader Customer Service

            Comment


              #7
              Hi JC,

              Yes I had taken a look at the Swing indicator code, and it seemed like it would only change the status of whether a bar is a swing high / low within "strength" bars ago. So if the strength is say 3 bars, it might change the status 3 bars ago depending on how the current bar progresses.

              However in this case, the error identified was 11 bars ago. I was using a swing setting of 2 bars. So whatever is happening in real-time to the current bar should not affect the status of the bar 11 bars ago.

              So I'm still stumped.

              Comment


                #8
                I'm trying the market replay to see if the problem can be replicated, and I found that sometimes the problem occurs in market replay, sometimes it doesn't.

                One quick question, when I call the function like so: lastSwingHigh = Swing(BarsArray[1], strength).SwingHighBar(0, 1, 90);

                Does a new Swing object get instantiated each time I call this, and all the historical ticks fed to this new Swing object to bring it up to date, before the value gets returned?

                or is there only 1 instance of the object which gets updated with the real-time ticks?

                If a new Swing object gets instantiated each time, how do I change that to the 2nd option: i.e. only instantiate 1 swing object which gets updated with real-time ticks.

                Comment


                  #9
                  Hello wintermelon,

                  It is my understanding that calling the indicator will create an instance of the indicator for the calculations of the Indicator to get the value of the SwingHighBar integer.

                  Typically, this is not an issue since it will have a very small performance difference that most will not notice. If you would like to try this more efficiently you may view the following thread.


                  You may want to save the real-time values and compare them as new bars are formed with the historical values of the Swing Indicator to get a better understanding of this.
                  JCNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks, I'm thinking whether the fact that a new Swing indicator is instantiated each time the SwingHighBar function is called, does that mean that each new instance would be fed the historical bars instead of the historical ticks, so effectively it will always be running as COBC = true, which is preventing it from triggering real-time?

                    Comment


                      #11
                      Hello wintermelon,

                      Any time you are loading/processing a NinjaScript file on Historical Data it will be processes as COBC = true. You can still have the indicator set to COBC = false, but the real-time processing will only happen after you have the script enabled and then each real-time tick of data the script will be processed.
                      JCNinjaTrader Customer Service

                      Comment


                        #12
                        Hi JC,

                        Yes I understand that. I am getting a bit confused from the reply by RyanM in the thread you posted. To recap:

                        * My indicator calls Swing(BarsArray[1], strength).SwingHighBar(0, 1, 90) on every bar update.
                        * My indicator is running COBC = false

                        Now when my indicator is running in real-time with incoming ticks, and it makes the Swing(BarsArray[1], strength).SwingHighBar(0, 1, 90) calls, is it

                        Case #1: A new instance of the Swing indicator is created with each call. The new instance is loaded with the historical bars (i.e. COBC = true) to bring it up to speed, and the required SwingHighBar value is returned. Hence the Swing indicator is always running in COBC = true, despite the fact that my indicator is running in real time with COBC = false.

                        OR

                        Case #2: RyanM's reply would mean that each time the Swing(BarsArray[1], strength).SwingHighBar(0, 1, 90) is called, it accesses the same instance of the Swing indicator that is stored in cache. A new instance is not created with each call. I presume that this single instance's OnBarUpdate will be called with the real-time ticks, hence the Swing indicator would be running as COBC = false.

                        Which is the correct scenario?

                        Comment


                          #13
                          wintermelon,

                          As long as you are accessing the same exact method with the same exact parameters, it will not create a new instance and the method will be cached. So in your example, Case #2 would be correct since it is the same method with the same data series, and parameters.
                          MatthewNinjaTrader Product Management

                          Comment


                            #14
                            Thanks Matthew.

                            I think I found the problem. I believe the Swing indicator has a bug when running in COBC = false.

                            The lastHighCache and the lastLowCache are only added using the first tick of the bar, and are not subsequently updated using the rest of the ticks of the same bar, hence when the comparison is done to determine swing highs and lows, it leads to incorrect results.

                            I have added the following piece of code to the "else" section which fixes the bug.

                            Code:
                            // update the caches
                            if (High[0] > (double) lastHighCache[lastHighCache.Count - 1])
                            	lastHighCache[lastHighCache.Count - 1] = High[0];
                            if (Low[0] < (double) lastLowCache[lastLowCache.Count - 1])
                            	lastLowCache[lastLowCache.Count - 1] = Low[0];
                            If you agree with the fix, you might want to update the indicator in the next release.

                            Comment


                              #15
                              Hello wintermelon,

                              I want to thank you for the work you have done with this indicator.
                              This has been a issue we have been trying to track down for a while and we appreciate your help.

                              I've been attempting to add these lines to the last else as there are no updates if that section is hit. I don't think this placement is correct as my results are not changing.

                              Would you mind directing me to the particular line where this modification should be placed?
                              I will do some testing with the Indicator and I will report my results back to you.


                              I look forward to working with you further.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by pechtri, 06-22-2023, 02:31 AM
                              10 responses
                              124 views
                              0 likes
                              Last Post Leeroy_Jenkins  
                              Started by judysamnt7, 03-13-2023, 09:11 AM
                              4 responses
                              59 views
                              0 likes
                              Last Post DynamicTest  
                              Started by ScottWalsh, Yesterday, 06:52 PM
                              4 responses
                              36 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by olisav57, Yesterday, 07:39 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post olisav57  
                              Started by trilliantrader, Yesterday, 03:01 PM
                              2 responses
                              22 views
                              0 likes
                              Last Post helpwanted  
                              Working...
                              X