Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

McClellan indicator discrepancy between Chart and Strategy

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

    McClellan indicator discrepancy between Chart and Strategy

    I have a multi-series strategy that runs on 1 minute bars (OnBarClose calculation, US Equities RTH) while McClellan indicator is driven by 30min data series. I have added ^Adv, ^Decl, and ES 30 minute series. The trade logic is trigger on BarsInProgress == 22, which is my 30 min ES series. I am printing the the McClellan indicator output to my NinjaScript output window to show the last 3 bars and printed at BarsInProgress == 22. I see that when I start the strategy I have an exact match to the McClellan indicator on the chart and they are in sync for the first 2 bars after RTH open; however by the 3rd bar, there is a discrepancy that can be as high as 60 or more after some time. This is a big problem as I need the zero cross to occur on the correct 30min bar.

    Any possible explanation for why a strategy indicator will fail to stay in sync with chart indicator? To ensure that McClellan has correct lookback data I have loaded 365 days on both chart and strategy and did the same for the Added Data series. It is evident that they are in sync because at start the values match precisely. What can I do to fix this?

    Edit:
    I uploaded a simple McClellanTest strategy that is simply printing out the values. Please check the output against a chart on 30min bars with McClellan indicator.
    Last edited by CyberNate; 09-29-2020, 04:17 PM.

    #2
    Click image for larger version  Name:	McClellan_discrepancy.PNG Views:	0 Size:	387.7 KB ID:	1120494
    Last edited by CyberNate; 09-29-2020, 04:08 PM.

    Comment


      #3
      Hello CyberNate,

      First, are you getting real-time data for the ^ADV and ^DECL?

      Is the strategy adding the indicator to the chart with AddChartIndicator()?

      Are you adding the indicator separately to the chart? Do you click away from the chart at any time?
      (Indicators added directly to the chart can be suspended when the chart tab is not selected, but when being used from AddChartIndicator())
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Yes, I pay for the CQG data feed that includes ADV, DECL, TICK, etc. Please run the test strategy and you'll see the same issue most likely.

        I use Market Replay, but the issue is the same with live data as well.

        Comment


          #5
          I see that if I disable Break at EOD (was enabled on both) on both the strategy and Chart that the synchronization will remain through the 1st day until the last bar. If I keep the strategy going, the next day it is out of sync.

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hello CyberNate,

            First, are you getting real-time data for the ^ADV and ^DECL?

            > Yes, through CQG package for index data.

            Is the strategy adding the indicator to the chart with AddChartIndicator()?
            ------------------------
            > No,

            private McClellanOscillator McClellanOscillator1;
            ...
            McClellanOscillator1 = McClellanOscillator(Closes[3], 19, 39);

            Is this not the right way? That's how I've always done it. I believe that AddChartIndicator() is for adding elements to the chart in case you are attaching strategy to a chart. I am running strategy separately, directly in Control Center. My chart is separate and has same settings with McClellan indicator.
            --------------------

            Are you adding the indicator separately to the chart? Do you click away from the chart at any time?
            (Indicators added directly to the chart can be suspended when the chart tab is not selected, but when being used from AddChartIndicator())
            > I add the indicator directly to the chart. It is always refreshing even if I'm not clicked into it.

            Please just run the strategy and you will see the issue for yourself. I have tried every setting including explicitly setting the Break at EOD in each added data series. Nothing works. It seems not possible to keep strategy in sync with a chart that has same settings.

            Edit: I have to retract the Break at EOD statement. It seems the behavior is inconsistent. Sometimes you'll see that strategy and indicator are close to being in sync, but then if you rerun the same data, can be different on the next run. This has been frustrating as I had seen that in my strategy and it took time to find the cause for inconsistent results after playing the same data multiple times. The difference between strategy and chart indicator varies widely so I can't even use an offset to account for it.
            Last edited by CyberNate; 09-29-2020, 06:12 PM.

            Comment


              #7
              Hello CyberNate,

              If you want values from an indicator in strategy to match an indicator on a chart, use AddChartIndicator() to add the indicator and this will use the same instance of the indicator on the chart and for the strategy and there will not be differences in settings, suspension, or values produced.

              Below is a link to the help guide.
              https://ninjatrader.com/support/help...tindicator.htm
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8

                Hello Chelsea,

                There is a bigger issue here. NinjaTrader is simply not consistent across instances. If you simply add McClellan Oscillator to a chart (no strategy involved) and then duplicate the chart, you will also see a difference between the charts. Why does this happen? If I add additional indicators on the chart that are also using ^ADV and ^DECL data, the indicator discrepancy is even greater. There seems to be a synchronization issue between the main data series and the ^ADV and ^DECL data series that are used for the indicator. How can I get consistency?

                Please keep in mind that this is Bar Close calculation, which should be the most simple case for synchronization. These are 30 minutes bars which should be easy enough to synchronize.


                Click image for larger version  Name:	chartdiscrepancy.PNG Views:	0 Size:	114.8 KB ID:	1120632
                Last edited by CyberNate; 09-30-2020, 11:01 AM.

                Comment


                  #9
                  Hello CyberNate,

                  The ES 09-20 is expired.

                  Using the ES 12-90 I am not able to reproduce this behavior using default settings while connected to a CQG/Continuum connection.

                  My guess would be that either you do not have real-time data or that the real-time values are different than the historical.

                  On a chart that updates the indicator every 30 minutes, I wouldn't expect the value to change until the bar closes.

                  If you open a ^DECL 30 minutes and wait 30 minutes for a bar to close, and then open a new ^DECL chart is the value on the chart new different that the first chart? (This would confirm the real-time data if the first chart has a bar close in real-time after 30 minutes and would confirm if the real-time values are different than the historical values.)
                  Can you do the same with ^ADV?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Perhaps that issue only occurs in Market Replay. I will check on live data with my simple strategy test. Thank you!

                    Comment


                      #11
                      I don't think you're grasping the issue here. I went ahead and added AddChartIndicator() to add my strategy, but of course that doesn't work because I run on 1 min bars and the indicator is driven by a secondary series, and really what is the point of that? It is just to display the indicator. The issue I have is that the data is WRONG. Look at how far off it gets in only a few bars That is a difference of 80 on the indicator. It makes my trade 1 or more bars late. I know the data is wrong because you can see that when viewing in another chart window and also other platforms that take the trade on the correct bar rather than 1 or 2 bars late. I need this indicator data to be correct and it is not when I run Market Replay, as well as live data. Please try for yourself with the sample strategy I had added here which is simply printing the McClellan output. How do you explain the huge difference between the strategy and another chart window with the EXACT same indicator settings as in the strategy? If I am doing something wrong, please tell me. You can't get much simpler than the test strategy that I attached which is inconsistent if you have another chart window open with the indicator.


                      Click image for larger version

Name:	McClellan_discrepancy2.PNG
Views:	37
Size:	217.0 KB
ID:	1120673

                      Comment


                        #12
                        Hello CyberNate,

                        An indicator processes data using the programmed logic in the script.

                        If the logic isn't changing, the data is.

                        Would you like to find out why the data is changing?

                        If the script is running on a secondary series, make a copy of the indicator that also adds a second series and calculates values with that series.
                        https://ninjatrader.com/support/foru...196#post820196

                        The point of using AddChartIndicator() is that the values from the strategy will exactly match the values on the chart, which what I was understanding you wanted.


                        I can explain differences by explaining differences in datafeeds, how historical data is processed, and by comparing real-time values with historical values.

                        As an example, some scripts don't process historical data.

                        Some data feeds don't have real-time data and the values on the values on the chart will change the moment a new chart is opened or the Reload All Historical Data is selected the chart.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by CyberNate View Post
                          private McClellanOscillator McClellanOscillator1;
                          ...
                          McClellanOscillator1 = McClellanOscillator(Closes[3], 19, 39);
                          That's probably not right.

                          @McClellanOscillator.cs doesn't seem to do anything with it Input, so passing
                          in Closes[3] doesn't make any sense to me.

                          Also, inside @McClellanOscillator.cs, it has this code,

                          Code:
                          else if (State == State.Configure)
                          {
                              AddDataSeries("^ADV");
                              AddDataSeries("^DECL");
                          }
                          I think you have to do an AddDataSeries for these same things in your
                          strategy .... Is that correct, ChelseaB?



                          Comment


                            #14
                            Originally posted by bltdavid View Post

                            That's probably not right.

                            @McClellanOscillator.cs doesn't seem to do anything with it Input, so passing
                            in Closes[3] doesn't make any sense to me.

                            Also, inside @McClellanOscillator.cs, it has this code,

                            Code:
                            else if (State == State.Configure)
                            {
                            AddDataSeries("^ADV");
                            AddDataSeries("^DECL");
                            }
                            I think you have to do an AddDataSeries for these same things in your
                            strategy .... Is that correct, ChelseaB?


                            Hello David,

                            Thank you for your time in reviewing.

                            That extra data series was to ensure that the indicator is fed 30 minute data series even if main strategy/chart series is different such as 1 min. It just hard codes 30 minute data feed to indicator. That's not the issue. It is also required that the strategy includes ^ADV and ^DECL when you access McClellan indicator. It is not enough that the indicator calls those data feeds.

                            Comment


                              #15
                              Hello bltdavid,

                              Yes, any host script must add the series added by any host script or an error will prevent the script from running.

                              Closes[3] would be the 4th added series of the strategy. Anything compared with this must have the same instrument, bar type, interval, and same amount of historical data as the 4th added series added to the strategy.

                              This adds a complexity and the calculations should be done similar to the example script I have posted in post #12.

                              That said, I made a simple strategy test script that adds the McClellanOscillator with only the primary series while connected to CQG/Continuum, then opened a second chart with the same instrument, bar type, interval, (30 min ES 12-20), with 5 days to load and the values are exactly the same. There are no differences.
                              Last edited by NinjaTrader_ChelseaB; 09-30-2020, 02:25 PM.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by tonynt, Today, 09:39 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post tonynt
                              by tonynt
                               
                              Started by ervin, Today, 09:23 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post ervin
                              by ervin
                               
                              Started by HansLenders, Today, 09:15 AM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_PatrickG  
                              Started by sdauteuil, Today, 08:23 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_PaulH  
                              Started by tonynt, Today, 08:27 AM
                              3 responses
                              21 views
                              0 likes
                              Last Post NinjaTrader_Heath  
                              Working...
                              X